[ty] Reject fixed tuples for non-inferable TypeVarTuples - #27943
Open
carljm wants to merge 1 commit into
Open
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 97.68%. The percentage of expected errors that received a diagnostic held steady at 93.44%. The number of fully passing files held steady at 109/136. |
Memory usage reportMemory usage unchanged ✅ |
|
carljm
changed the base branch from
main
to
cjm/ty-invariant-gradual-tuple-materialization
August 21, 2026 01:12
carljm
force-pushed
the
cjm/ty-4342-fixed-variadic-tuples
branch
from
August 21, 2026 01:12
9d31f5c to
dac40d1
Compare
carljm
marked this pull request as ready for review
August 21, 2026 01:46
carljm
marked this pull request as draft
August 21, 2026 02:33
carljm
changed the base branch from
cjm/ty-invariant-gradual-tuple-materialization
to
cjm/ty-typevartuple-unknown-recovery
August 21, 2026 03:47
carljm
force-pushed
the
cjm/ty-4342-fixed-variadic-tuples
branch
from
August 21, 2026 03:48
dac40d1 to
26e094c
Compare
carljm
marked this pull request as ready for review
August 21, 2026 04:01
dhruvmanila
approved these changes
Aug 21, 2026
Comment on lines
+370
to
+371
| def reject_empty[*Ts](values: tuple[*Ts]) -> tuple[*Ts]: | ||
| return () # error: [invalid-return-type] |
Member
There was a problem hiding this comment.
This does raise a question on what to do for narrowing like:
def reject_empty[*Ts](values: tuple[*Ts]) -> tuple[*Ts]:
if len(values) == 0:
# error on this branch but should it?
return values
return () # error: [invalid-return-type]Both Pyright and mypy don't error on the first return statement, pyrefly errors on both return statements.
This can also be fixed in follow-up but it would be useful to have a test case for it.
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.
On main, a function returning
tuple[*Ts]can wrongly return an unrelated fixed-length tuple without an error. For example, returning()from a variadic-identity function caused ty to infer a nonempty tuple at call sites even though the runtime result was an empty tuple.Only expand a non-inferable
TypeVarTupletarget when the source tuple is variable-length. Fixed tuples now reach the ordinary type-variable rejection instead of repeating the same tuple comparison and succeeding through the recursion guard. Inference and explicit constraint assumptions keep their existing behavior.Depends on #27950 to avoid cascading errors after a missing
TypeVarTupleunpack, and transitively on #27946 to preserve exhaustiveness for variadic class patterns.Fixes astral-sh/ty#4342.
Test plan
Added mdtests for empty and nonempty fixed returns, annotated assignments, matching tuple prefixes and suffixes, subtyping, and fixed tuples containing
AnyorNever. Constraint-implication coverage checks that an applicable assumption permits the relationship while incompatible elements and unconstrained packs remain rejected.