Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match: Incorrect "Incompatible types in capture pattern" when type has already been narrowed #16736

Open
JelleZijlstra opened this issue Jan 2, 2024 · 0 comments · May be fixed by #18155
Open
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement

Comments

@JelleZijlstra
Copy link
Member

x: int | None
y: int
match x:
    case None:
        pass
    case y:
        pass
main.py:6: error: Incompatible types in capture pattern (pattern captures type "int | None", variable has type "int")  [misc]

https://mypy-play.net/?mypy=latest&python=3.10&gist=b3423e1eab3afadc8e4d172761d256a2

This should be fine, because the previous case ensured that y is not None.

I ran into this in a real use case.

@JelleZijlstra JelleZijlstra added bug mypy got something wrong topic-match-statement Python 3.10's match statement labels Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant