Skip to content

Fix false positive for NamedTuple subtype of TupleType#21529

Open
JiwaniZakir wants to merge 1 commit into
python:masterfrom
JiwaniZakir:fix/issue-21528
Open

Fix false positive for NamedTuple subtype of TupleType#21529
JiwaniZakir wants to merge 1 commit into
python:masterfrom
JiwaniZakir:fix/issue-21528

Conversation

@JiwaniZakir
Copy link
Copy Markdown
Contributor

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

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[1.19 regression] copy.replace doesn't work with NamedTuple anymore

1 participant