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
I expect this code to typecheck, since
AandBare nominally different. Note that changing the field type or adding additional fields results inAandBno 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:
resulting mypy error: