File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -947,6 +947,34 @@ def f2(x: Custom | None):
947947 reveal_type(x) # N: Revealed type is "__main__.Custom | None"
948948[builtins fixtures/dict.pyi]
949949
950+ [case testNarrowingCustomEqualityUnion2]
951+ # flags: --strict-equality --warn-unreachable
952+ from __future__ import annotations
953+ from typing import Any
954+
955+ class Custom:
956+ def __eq__(self, other: object) -> bool:
957+ raise
958+
959+ def f3(x: str | Custom, y: str | int):
960+ if x == y:
961+ reveal_type(x) # N: Revealed type is "builtins.str | __main__.Custom"
962+ reveal_type(y) # N: Revealed type is "builtins.str | builtins.int"
963+ else:
964+ reveal_type(x) # N: Revealed type is "builtins.str | __main__.Custom"
965+ reveal_type(y) # N: Revealed type is "builtins.str | builtins.int"
966+
967+ def f4(x: str | Any, y: str | int):
968+ if x == y:
969+ reveal_type(x) # N: Revealed type is "builtins.str | Any | builtins.int"
970+ reveal_type(y) # N: Revealed type is "builtins.str | builtins.int"
971+ else:
972+ reveal_type(x) # N: Revealed type is "builtins.str | Any"
973+ reveal_type(y) # N: Revealed type is "builtins.str | builtins.int"
974+
975+
976+ [builtins fixtures/dict.pyi]
977+
950978[case testNarrowingCustomEqualityUnionTypeTarget]
951979# flags: --strict-equality --warn-unreachable
952980from __future__ import annotations
Original file line number Diff line number Diff line change @@ -1674,3 +1674,20 @@ def x() -> None:
16741674main:4: error: Statement is unreachable
16751675 if 5:
16761676 ^~~~~
1677+
1678+ [case testReachableEqualityNarrowingAny]
1679+ # flags: --warn-unreachable
1680+ from __future__ import annotations
1681+ from typing import Any
1682+
1683+ def print(s: str): pass
1684+
1685+ def main(contents: Any, commit: str | None) -> None:
1686+ if (
1687+ contents.get("commit") == commit
1688+ and (commit is not None or print("can_be_reached"))
1689+ ):
1690+ pass
1691+
1692+ main({"commit": None}, None)
1693+ [builtins fixtures/tuple.pyi]
You can’t perform that action at this time.
0 commit comments