Skip to content

Support PEP 696 – Type defaults for TypeVarLikes #14851

Description

@intgr

Feature

See PEP 696 – Type defaults for TypeVarLikes for details. The PEP has not yet been accepted though. Example from the PEP:

T=TypeVar("T", default=int) # This means that if no type is specified T = int@dataclassclassBox(Generic[T]):
value: T|None=Nonereveal_type(Box()) # type is Box[int]reveal_type(Box(value="Hello World!")) # type is Box[str]

Since I did not find an existing tracking issue for this feature, I decided to open one.

The default= argument is already supported in typing_extensionsversion 4.4.0+ and typeshed (python/typeshed#8821)


Edit from maintainer: mypy supports basic PEP 696 use cases, but is missing some support for less common use cases. Give it a try!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions