[ty] Add validation for type parameters with defaults after TypeVarTuple#23807
Merged
AlexWaygood merged 2 commits intomainfrom Mar 8, 2026
Merged
Conversation
…ypeVarTuples in parameter lists
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 87.10%. The percentage of expected errors that received a diagnostic held steady at 77.81%. The number of fully passing files held steady at 63/131. |
|
Memory usage reportMemory usage unchanged ✅ |
|
Member
Author
|
It seems the conformance suite only has tests for this check for legacy type parameters, not PEP-695 type parameters, and the legacy-parameter bit is the bit I deferred for now. But I think this is a worthwhile check to add anyway; it catches a |
2bb61fa to
0bc361c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds validation to enforce PEP 695 type parameter ordering rules. Specifically, it prevents type parameters with defaults from following a
TypeVarTuplein both generic classes and type aliases, as this is prohibited by the typing spec.The validation is necessary because a
TypeVarTupleconsumes all remaining positional type arguments, making any subsequent type parameters with defaults meaningless and ambiguous.In due course, we need to enforce the same thing for legacy type variables as well, but attempting that got pretty hacky while we're still in a position where we don't have
TypeVarTuplesupport elsewhere, so I left it for now.Note that pyrefly complains about this, with a PEP-695 function -- but no other type checker does, so I decided not to complain about this. It's weird (why would you write this?), but functions can't be explicitly specialized, so I don't see anything wrong with it in the same way as with type aliases and classes:
Test Plan
mdtests and snapshots