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

Expand TypeVarTuple default (PEP 696) #16851

Merged
merged 2 commits into from
Feb 3, 2024

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Feb 1, 2024

Small change to fix an error when expanding a TypeVarTuple default.

RuntimeError: Invalid type replacement to expand: Unpack[tuple[builtins.int, builtins.str]]

Ref: #14851

@cdce8p cdce8p force-pushed the TypeVar-09-expand-TypeVarTuple branch from 7e08baf to 3f69b90 Compare February 1, 2024 21:07
@cdce8p cdce8p added the topic-pep-696 TypeVar defaults label Feb 1, 2024
Comment on lines 1542 to +1544
# WARNING: do not increase this number unless absolutely necessary,
# and you understand what you are doing.
ALLOWED_GET_PROPER_TYPES = 8
ALLOWED_GET_PROPER_TYPES = 9
Copy link
Collaborator Author

@cdce8p cdce8p Feb 1, 2024

Choose a reason for hiding this comment

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

@JelleZijlstra The test here just counts all get_proper_type calls inside expandtype. I believe the change still makes sense and is necessary to be able to compare the type inside Unpack. Furthermore, it's guarded by the isinstance check so the performance penalty should probably be minimal. Let me know what you think.

No other test case so far would reach that, only the new TypeVarTuple default ones.

Copy link
Contributor

github-actions bot commented Feb 1, 2024

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

@JelleZijlstra JelleZijlstra merged commit 3804f7e into python:master Feb 3, 2024
18 checks passed
@cdce8p cdce8p deleted the TypeVar-09-expand-TypeVarTuple branch February 3, 2024 07:51
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