Repository navigation
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 98.15%. The percentage of expected errors that received a diagnostic held steady at 98.07%. The number of fully passing files held steady at 133/146. |
Memory usage reportMemory usage unchanged ✅ |
|
carljm
requested review from
AlexWaygood
and removed request for
charliermarsh
September 21, 2026 22:11
carljm
marked this pull request as draft
September 24, 2026 17:12
This branch has not been deployed
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.
Iteration over a tuple subclass currently uses its stored element types even when the class overrides
__iter__.It would be reasonable to consider an override of
__iter__on a tuple subclass that changes iteration behavior (and why else would you override__iter__, if not to change iteration?) to be inherently a Liskov violation, if iteration behavior is part of the core of what it means to be a tuple. So we could choose to error on tuple subclasses overriding__iter__.But it seems to me that even if we also do that, it's still better to have this change than not to have it. The added complexity is minimal, the perf impact is not detectable (there's zero cost for regular tuples, which are the vast majority in real-world code), and the result is that we are less likely to make blatantly wrong conclusions in the rare case of code that does this. Even if we want to error on tuple subclasses implementing
__iter__, why would we not also want to be less wrong in our type inference of code using such subclasses?Use the tuple's stored element types when its method resolution order reaches
tuplebefore finding an__iter__override. Otherwise, infer iteration through the visible iterator method. Basetupleannotations continue to use builtin tuple behavior; the guard handles overrides visible on the supplied subclass type.Follow-up to #28676.
Test plan
Mdtests cover subclasses inheriting
tuple.__iter__, direct and inherited overrides that yield no elements, and mixins before and aftertuplein the method resolution order. They verify tuple conversion, loop element types, and membership after starred unpacking, including an override that yields different values from those stored in the tuple.