Fix false positive for NamedTuple subtype of TupleType#21529
Open
JiwaniZakir wants to merge 1 commit into
Open
Fix false positive for NamedTuple subtype of TupleType#21529JiwaniZakir wants to merge 1 commit into
JiwaniZakir wants to merge 1 commit into
Conversation
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
When checking whether an Instance (specifically a NamedTuple instance) is a subtype of a TupleType, mypy incorrectly returned False even though the NamedTuple and its TupleType representation refer to the same underlying type. The fix is in mypy/subtypes.py in the SubtypeVisitor.visit_instance method: when the mapped type is a NamedTuple and shares its TypeInfo with the right-hand TupleType's partial fallback, we now return True. To verify, create a NamedTuple and assign it to a variable typed as the equivalent tuple; mypy should no longer report a false positive error.
Fixes #21528