Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion mypy/meet.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
find_unpack_in_list,
get_proper_type,
get_proper_types,
is_named_instance,
split_with_prefix_and_suffix,
)

Expand Down Expand Up @@ -645,7 +646,18 @@ def are_tuples_overlapping(

if len(left.items) != len(right.items):
return False
return all(is_overlapping(l, r) for l, r in zip(left.items, right.items))
if not all(is_overlapping(l, r) for l, r in zip(left.items, right.items)):
return False

# Check that the tuples aren't from e.g. different NamedTuples.
if is_named_instance(right.partial_fallback, "builtins.tuple") or is_named_instance(
left.partial_fallback, "builtins.tuple"
):
return True
else:
return is_subtype(left.partial_fallback, right.partial_fallback) or is_subtype(
right.partial_fallback, left.partial_fallback
)


def expand_tuple_if_possible(tup: TupleType, target: int) -> TupleType:
Expand Down
16 changes: 16 additions & 0 deletions test-data/unit/check-namedtuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -1474,3 +1474,19 @@ def main(n: NT[T]) -> None:

[builtins fixtures/tuple.pyi]
[typing fixtures/typing-namedtuple.pyi]

[case testNamedTupleOverlappingCheck]
from typing import overload, NamedTuple, Union

class A(NamedTuple): ...

class B(NamedTuple): ...

@overload
def f(arg: A) -> A: ...
@overload
def f(arg: B) -> B: ...
def f(arg: Union[A, B]) -> Union[A, B]: ...

# no errors should be raised above.
[builtins fixtures/tuple.pyi]
Loading