Open
Description
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
@dataclass
class Box(Generic[T]):
value: T | None = None
reveal_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_extensions
version 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!