Skip to content

add bound syntax for type variable tuples and parameter specifications #148945

@KotlinIsland

Description

@KotlinIsland

Feature or enhancement

Proposal:

# typical forms
class A[T: int, *Ts: int, **P: [int]]: ...
A[
    str, # error
    int, # ok, matching Ts bound
    str, # error, not matching Ts bound
    [str], # error, not matching P bound
]

A[
    int, # ok
    int, # ok, matching Ts bound
    bool, # ok, matching Ts bound
    [int], # ok, matching P bound
]

# tvt unpacked form
class B[*Ts: *tuple[int, str]]: ...

B[
    int, # ok
    int, # error, not subtype of str
    int, # error, too many types
]

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/parameter-specification-and-type-variable-tuple-should-support-bounds/107068/6

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions