@@ -2135,7 +2135,7 @@ else:
21352135# mypy: strict-equality
21362136from __future__ import annotations
21372137from typing import Any
2138- from enum import IntEnum, StrEnum
2138+ from enum import IntEnum
21392139
21402140class IE(IntEnum):
21412141 X = 1
@@ -2178,6 +2178,71 @@ def f5(x: int) -> None:
21782178 reveal_type(x) # N: Revealed type is "builtins.int"
21792179 else:
21802180 reveal_type(x) # N: Revealed type is "Literal[__main__.IE.X]"
2181+
2182+ def f6(x: IE) -> None:
2183+ if x == IE.X:
2184+ reveal_type(x) # N: Revealed type is "Literal[__main__.IE.X]"
2185+ else:
2186+ reveal_type(x) # N: Revealed type is "Literal[__main__.IE.Y]"
2187+ [builtins fixtures/primitives.pyi]
2188+
2189+ [case testNarrowingWithIntEnum2]
2190+ # mypy: strict-equality
2191+ from __future__ import annotations
2192+ from typing import Any
2193+ from enum import IntEnum, Enum
2194+
2195+ class MyDecimal: ...
2196+
2197+ class IE(IntEnum):
2198+ X = 1
2199+ Y = 2
2200+
2201+ class IE2(IntEnum):
2202+ X = 1
2203+ Y = 2
2204+
2205+ class E(Enum):
2206+ X = 1
2207+ Y = 2
2208+
2209+ def f1(x: IE | MyDecimal) -> None:
2210+ if x == IE.X:
2211+ reveal_type(x) # N: Revealed type is "Union[__main__.IE, __main__.MyDecimal]"
2212+ else:
2213+ reveal_type(x) # N: Revealed type is "Union[__main__.IE, __main__.MyDecimal]"
2214+
2215+ def f2(x: E | bytes) -> None:
2216+ if x == E.X:
2217+ reveal_type(x) # N: Revealed type is "Literal[__main__.E.X]"
2218+ else:
2219+ reveal_type(x) # N: Revealed type is "Union[Literal[__main__.E.Y], builtins.bytes]"
2220+
2221+ def f3(x: IE | IE2) -> None:
2222+ if x == IE.X:
2223+ reveal_type(x) # N: Revealed type is "Union[__main__.IE, __main__.IE2]"
2224+ else:
2225+ reveal_type(x) # N: Revealed type is "Union[__main__.IE, __main__.IE2]"
2226+
2227+ def f4(x: IE | E) -> None:
2228+ if x == IE.X:
2229+ reveal_type(x) # N: Revealed type is "Literal[__main__.IE.X]"
2230+ elif x == E.X:
2231+ reveal_type(x) # N: Revealed type is "Literal[__main__.E.X]"
2232+ else:
2233+ reveal_type(x) # N: Revealed type is "Union[Literal[__main__.IE.Y], Literal[__main__.E.Y]]"
2234+
2235+ def f5(x: E | str | int) -> None:
2236+ if x == E.X:
2237+ reveal_type(x) # N: Revealed type is "Literal[__main__.E.X]"
2238+ else:
2239+ reveal_type(x) # N: Revealed type is "Union[Literal[__main__.E.Y], builtins.str, builtins.int]"
2240+
2241+ def f6(x: IE | Any) -> None:
2242+ if x == IE.X:
2243+ reveal_type(x) # N: Revealed type is "Union[__main__.IE, Any]"
2244+ else:
2245+ reveal_type(x) # N: Revealed type is "Union[__main__.IE, Any]"
21812246[builtins fixtures/primitives.pyi]
21822247
21832248[case testNarrowingWithStrEnum]
@@ -2205,4 +2270,10 @@ def f3(x: object) -> None:
22052270 reveal_type(x) # N: Revealed type is "builtins.object"
22062271 else:
22072272 reveal_type(x) # N: Revealed type is "builtins.object"
2273+
2274+ def f4(x: SE) -> None:
2275+ if x == SE.A:
2276+ reveal_type(x) # N: Revealed type is "Literal[__main__.SE.A]"
2277+ else:
2278+ reveal_type(x) # N: Revealed type is "Literal[__main__.SE.B]"
22082279[builtins fixtures/primitives.pyi]
0 commit comments