Skip to content

Commit 953c9a0

Browse files
committed
.
1 parent bd5b3e2 commit 953c9a0

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

test-data/unit/check-narrowing.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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
952980
from __future__ import annotations

test-data/unit/check-unreachable-code.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,3 +1674,20 @@ def x() -> None:
16741674
main: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]

0 commit comments

Comments
 (0)