Skip to content

Allow specifying a default for omitted type parameters #307

Description

@refi64

Take the following class:

classBase: passclassDerived(Base): passT=TypeVar('T', bound=Base)
classMyType(Generic[T]):
passmyvar: MyType=None# type of `myvar` is `MyType[Any]`

My idea is to allow for some way to specify a default other than any when the parameters are omitted. For example:

classBase: passclassDerived(Base): passT=TypeVar('T', bound=Base, default=Base)
classMyType(Generic[T]):
passmyvar: MyType=None# type of `myvar` is `MyType[Base]`

or (I know this is invalid syntax, but it's the idea that counts):

classBase: passclassDerived(Base): passT=TypeVar('T', bound=Base)
classMyType(Generic[T, default=Base]):
passmyvar: MyType=None# type of `myvar` is `MyType[Base]`

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions