-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normaltopic-named-tupletopic-overloads
Description
I expect this code to typecheck, since A
and B
are nominally different. Note that changing the field type or adding additional fields results in A
and B
no longer being considered overlapping, but changing the field name does not, so it appears that type-identity for NamedTuples is determined solely by field type and order.
This is python 3.6.4 and mypy 0.700. I have not attempted to reproduce using git-master.
repro:
# foobar.py
from typing import NamedTuple, overload
A = NamedTuple("A", (("f", int),))
B = NamedTuple("B", (("q", int),))
@overload
def plain(a: A) -> int:
...
@overload
def plain(a: B) -> str:
...
def plain(a):
if isinstance(a, A):
return 4
elif isinstance(a, B):
return "4"
else:
raise TypeError()
resulting mypy error:
foobar.py:9: error: Overloaded function signatures 1 and 2 overlap with incompatible return types
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normaltopic-named-tupletopic-overloads