[ty] Prove TypedDict structural patterns exhaustive#26285
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.47%. The percentage of expected errors that received a diagnostic held steady at 89.19%. The number of fully passing files held steady at 95/134. |
Memory usage reportMemory usage unchanged ✅ |
|
8f587b7 to
cc872c0
Compare
bb214c4 to
d86cf11
Compare
cc872c0 to
40451ee
Compare
d86cf11 to
acc9024
Compare
40451ee to
e992ca4
Compare
acc9024 to
e8cc088
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
e992ca4 to
d3b1672
Compare
e8cc088 to
2316ebb
Compare
d3b1672 to
724661e
Compare
2316ebb to
cfbac08
Compare
dhruvmanila
approved these changes
Jun 25, 2026
724661e to
dc19cb4
Compare
Base automatically changed from
charlie/positional-class-pattern-exhaustiveness
to
main
June 25, 2026 11:35
cfbac08 to
feed4cb
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 is the third and final stacked PR split from #26010. It is based on #26284.
Prior to this change, we retained only whether a mapping pattern was empty or nonempty. That is enough to recognize
case {}as exhaustive for a mapping, but it cannot prove that a keyed pattern matches every value of aTypedDict. We also modelTypedDictstructurally rather than as a nominaldictsubtype, even though everyTypedDictvalue is a dictionary at runtime.This retains each mapping key and nested pattern for subject-aware exhaustiveness. A keyed mapping pattern is exhaustive for a
TypedDictonly when every key is a string literal naming a required field and every nested pattern exhausts that field's declared type. Optional, absent, and non-string keys remain refutable.The same runtime representation rule lets argumentless
dictandMappingclass patterns, along with the positionaldictmatch-self pattern, exhaust aTypedDictsubject. Negative narrowing reuses the resulting definite-match type instead of treating every nonempty mapping pattern as opaque.