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 initial support for new style TypeVar defaults (PEP 696) #17985

Merged
merged 6 commits into from
Oct 19, 2024

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Oct 17, 2024

Add initial support for TypeVar defaults using the new syntax. Similar to the old syntax, it doesn't fully work yet for ParamSpec, TypeVarTuple and recursive TypeVar defaults.

Refs: #14851

@cdce8p cdce8p added the topic-pep-696 TypeVar defaults label Oct 17, 2024

This comment has been minimized.

This comment has been minimized.

class ClassTs2[*Ts = *tuple[int, ...]]: ...
[builtins fixtures/tuple.pyi]

[case testPEP695TypeParameterDefaultInvalid]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no invalid tests for functions, and I couldn't find code that would error for bad defaults on generic functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5f8e69c with a small exception for when the TypeVar isn't used in the function signature. In that case the TypeVar isn't actually bound to the tvar_scope. Fixing that would probably require a bit more work. Left it as a TODO for now.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JelleZijlstra JelleZijlstra merged commit 603a365 into python:master Oct 19, 2024
18 checks passed
@cdce8p cdce8p deleted the new-syntax-TypeVar-defaults branch October 19, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-pep-696 TypeVar defaults
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants