Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PEP 696 #216

Closed
Fatal1ty opened this issue Apr 21, 2024 · 0 comments · Fixed by #217
Closed

Add support for PEP 696 #216

Fatal1ty opened this issue Apr 21, 2024 · 0 comments · Fixed by #217
Assignees
Labels
enhancement New feature or request

Comments

@Fatal1ty
Copy link
Owner

Fatal1ty commented Apr 21, 2024

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.

@Fatal1ty Fatal1ty added the enhancement New feature or request label Apr 21, 2024
@Fatal1ty Fatal1ty self-assigned this Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant