Skip to content

Commit

Permalink
Add regression test cases (#17869)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja authored Oct 5, 2024
1 parent 16ba7f4 commit 4e4826f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test-data/unit/check-narrowing.test
Original file line number Diff line number Diff line change
Expand Up @@ -2291,3 +2291,45 @@ def f4(x: SE) -> None:
else:
reveal_type(x) # N: Revealed type is "Literal[__main__.SE.B]"
[builtins fixtures/primitives.pyi]

[case testConsistentNarrowingEqAndIn]
# flags: --python-version 3.10

# https://github.com/python/mypy/issues/17864
def f(x: str | int) -> None:
if x == "x":
reveal_type(x) # N: Revealed type is "Union[builtins.str, builtins.int]"
y = x

if x in ["x"]:
# TODO: we should fix this reveal https://github.com/python/mypy/issues/3229
reveal_type(x) # N: Revealed type is "Union[builtins.str, builtins.int]"
y = x
z = x
z = y
[builtins fixtures/primitives.pyi]

[case testConsistentNarrowingInWithCustomEq]
# flags: --python-version 3.10

# https://github.com/python/mypy/issues/17864
class C:
def __init__(self, x: int) -> None:
self.x = x

def __eq__(self, other: object) -> bool:
raise
# Example implementation:
# if isinstance(other, C) and other.x == self.x:
# return True
# return NotImplemented

class D(C):
pass

def f(x: C) -> None:
if x in [D(5)]:
reveal_type(x) # D # N: Revealed type is "__main__.C"

f(C(5))
[builtins fixtures/primitives.pyi]

0 comments on commit 4e4826f

Please sign in to comment.