Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,14 @@ def is_singleton_equality_type(typ: ProperType) -> bool:
Returns True if every value of this type compares equal to every other value of this type,
as judged by the `==` operator.
"""
return isinstance(typ, LiteralType) or is_singleton_identity_type(typ)
return (
isinstance(typ, LiteralType)
or is_singleton_identity_type(typ)
or (
isinstance(typ, TupleType)
and all(is_singleton_equality_type(get_proper_type(t)) for t in typ.items)
)
)


def try_expanding_sum_type_to_union(typ: Type, target_fullname: str | None) -> Type:
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-narrowing.test
Original file line number Diff line number Diff line change
Expand Up @@ -4281,3 +4281,12 @@ def func(y: H) -> H:
else:
return y
[builtins fixtures/primitives.pyi]

[case testNarrowTupleOfSingletons]
# flags: --strict-equality --warn-unreachable
def f(a: tuple[int, str] | tuple[None, None]):
if a != (None, None):
reveal_type(a) # N: Revealed type is "tuple[builtins.int, builtins.str]"
else:
reveal_type(a) # N: Revealed type is "tuple[None, None]"
[builtins fixtures/primitives.pyi]
Loading