Is your feature request related to a problem? Please describe.
PEP 695 introduces the concept of type defaults for type parameters, including TypeVar and TypeVarTuple, which act as defaults for type parameters for which no type is specified. We can use this new information in the same way as we do with bound parameter.
Describe the solution you'd like
Use the new __default__ parameter on a par with the __bound__ parameter giving priority to the first.
The following examples will be equivalent (we will assume x to be int):
T = TypeVar("T", default=int)
@dataclass
class MyClass(Generic[T]):
x: T
T = TypeVar("T", bound=int)
@dataclass
class MyClass(Generic[T]):
x: T
@dataclass
class MyClass[T: int]:
x: T
Additional context
We should support this new PEP for TypeVarTuple as well. All the examples from PEP 696 can be used in new tests.
Is your feature request related to a problem? Please describe. PEP 695 introduces the concept of type defaults for type parameters, including
TypeVar
andTypeVarTuple
, which act as defaults for type parameters for which no type is specified. We can use this new information in the same way as we do withbound
parameter.Describe the solution you'd like Use the new
__default__
parameter on a par with the__bound__
parameter giving priority to the first.The following examples will be equivalent (we will assume
x
to beint
):Additional context We should support this new PEP for
TypeVarTuple
as well. All the examples from PEP 696 can be used in new tests.