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 @@ -2206,3 +2206,45 @@ def f3(x: object) -> None:
22062206 else:
22072207 reveal_type(x) # N: Revealed type is "builtins.object"
22082208[builtins fixtures/primitives.pyi]
2209+
2210+ [case testConsistentNarrowingEqAndIn]
2211+ # flags: --python-version 3.10
2212+
2213+ # https://github.com/python/mypy/issues/17864
2214+ def f(x: str | int) -> None:
2215+ if x == "x":
2216+ reveal_type(x) # N: Revealed type is "Union[builtins.str, builtins.int]"
2217+ y = x
2218+
2219+ if x in ["x"]:
2220+ # TODO: we should fix this reveal https://github.com/python/mypy/issues/3229
2221+ reveal_type(x) # N: Revealed type is "Union[builtins.str, builtins.int]"
2222+ y = x
2223+ z = x
2224+ z = y
2225+ [builtins fixtures/primitives.pyi]
2226+
2227+ [case testConsistentNarrowingInWithCustomEq]
2228+ # flags: --python-version 3.10
2229+
2230+ # https://github.com/python/mypy/issues/17864
2231+ class C:
2232+ def __init__(self, x: int) -> None:
2233+ self.x = x
2234+
2235+ def __eq__(self, other: object) -> bool:
2236+ raise
2237+ # Example implementation:
2238+ # if isinstance(other, C) and other.x == self.x:
2239+ # return True
2240+ # return NotImplemented
2241+
2242+ class D(C):
2243+ pass
2244+
2245+ def f(x: C) -> None:
2246+ if x in [D(5)]:
2247+ reveal_type(x) # D # N: Revealed type is "__main__.C"
2248+
2249+ f(C(5))
2250+ [builtins fixtures/primitives.pyi]
You can’t perform that action at this time.
0 commit comments