used-before-def incorrectly flagged when using match/case with a walrus operator #14659
Labels
bug
mypy got something wrong
topic-match-statement
Python 3.10's match statement
topic-possibly-undefined
possibly-undefined error code
Bug Report
When you use a walrus operator in a
match
statement mypy will complain about an used-before-def for any use of the variable after the first case. (It doesn't complain for the first case)To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=f0900514987ceef340db8076b6319cd8
Expected Behavior
I'm pretty sure the code is fine and that there's no way the variable is actually undefined. I also realize that I can rewrite the code to be
case 5 as value:
to work around the issue. Also, I realize the example is trivial but imagine if the5
wasint()
.Actual Behavior
main.py:6: error: Name "result" is used before definition [used-before-def]
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: