match: Incorrect "Incompatible types in capture pattern" when type has already been narrowed #16736
Open
Description
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.