File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -2291,3 +2291,45 @@ def f4(x: SE) -> None:
2291
2291
else:
2292
2292
reveal_type(x) # N: Revealed type is "Literal[__main__.SE.B]"
2293
2293
[builtins fixtures/primitives.pyi]
2294
+
2295
+ [case testConsistentNarrowingEqAndIn]
2296
+ # flags: --python-version 3.10
2297
+
2298
+ # https://github.com/python/mypy/issues/17864
2299
+ def f(x: str | int) -> None:
2300
+ if x == "x":
2301
+ reveal_type(x) # N: Revealed type is "Union[builtins.str, builtins.int]"
2302
+ y = x
2303
+
2304
+ if x in ["x"]:
2305
+ # TODO: we should fix this reveal https://github.com/python/mypy/issues/3229
2306
+ reveal_type(x) # N: Revealed type is "Union[builtins.str, builtins.int]"
2307
+ y = x
2308
+ z = x
2309
+ z = y
2310
+ [builtins fixtures/primitives.pyi]
2311
+
2312
+ [case testConsistentNarrowingInWithCustomEq]
2313
+ # flags: --python-version 3.10
2314
+
2315
+ # https://github.com/python/mypy/issues/17864
2316
+ class C:
2317
+ def __init__(self, x: int) -> None:
2318
+ self.x = x
2319
+
2320
+ def __eq__(self, other: object) -> bool:
2321
+ raise
2322
+ # Example implementation:
2323
+ # if isinstance(other, C) and other.x == self.x:
2324
+ # return True
2325
+ # return NotImplemented
2326
+
2327
+ class D(C):
2328
+ pass
2329
+
2330
+ def f(x: C) -> None:
2331
+ if x in [D(5)]:
2332
+ reveal_type(x) # D # N: Revealed type is "__main__.C"
2333
+
2334
+ f(C(5))
2335
+ [builtins fixtures/primitives.pyi]
You can’t perform that action at this time.
0 commit comments