@@ -1005,6 +1005,50 @@ def f(x: Custom | None, y: int | None):
10051005 reveal_type(y) # N: Revealed type is "builtins.int | None"
10061006[builtins fixtures/primitives.pyi]
10071007
1008+ [case testNarrowingCustomEqualityUnion4]
1009+ # flags: --strict-equality --warn-unreachable
1010+ from __future__ import annotations
1011+ from typing import Any
1012+
1013+ class Custom1:
1014+ def __eq__(self, other: object) -> bool:
1015+ raise
1016+
1017+ class Custom2:
1018+ def __eq__(self, other: object) -> bool:
1019+ raise
1020+
1021+ def f(x: Custom1 | int, y: Custom2 | int):
1022+ if x == y:
1023+ reveal_type(x) # N: Revealed type is "__main__.Custom1 | builtins.int"
1024+ reveal_type(y) # N: Revealed type is "__main__.Custom2 | builtins.int"
1025+ else:
1026+ reveal_type(x) # N: Revealed type is "__main__.Custom1 | builtins.int"
1027+ reveal_type(y) # N: Revealed type is "__main__.Custom2 | builtins.int"
1028+ [builtins fixtures/primitives.pyi]
1029+
1030+ [case testNarrowingCustomEqualitySubclass]
1031+ # flags: --strict-equality --warn-unreachable
1032+ from __future__ import annotations
1033+ from typing import Any
1034+
1035+ class Custom:
1036+ def __eq__(self, other: object) -> bool:
1037+ raise
1038+
1039+ class CustomSub(Custom):
1040+ def __eq__(self, other: object) -> bool:
1041+ raise
1042+
1043+ def f(x: Custom, y: CustomSub):
1044+ if x == y:
1045+ reveal_type(x) # N: Revealed type is "__main__.Custom"
1046+ reveal_type(y) # N: Revealed type is "__main__.CustomSub"
1047+ else:
1048+ reveal_type(x) # N: Revealed type is "__main__.Custom"
1049+ reveal_type(y) # N: Revealed type is "__main__.CustomSub"
1050+ [builtins fixtures/tuple.pyi]
1051+
10081052[case testNarrowingUnreachableCases]
10091053# flags: --strict-equality --warn-unreachable
10101054from typing import Literal, Union
0 commit comments