Two possibly-undefined
bugs with match
statements
#15958
Labels
bug
mypy got something wrong
topic-match-statement
Python 3.10's match statement
topic-possibly-undefined
possibly-undefined error code
topic-reachability
Detecting unreachable code
Bug Report
We're seeing two bugs relating to the
possibly-undefined
error code over at python/cpython#108454To Reproduce
repro.py
mypy --enable-error-code=possibly-undefined repro.py
mypy --enable-error-code=possibly-undefined repro.py --warn-unreachable
Expected Behavior
Neither invocation of mypy should result in any errors being emitted. The
match
statement is an exhaustive match, so there's no possibility thatf
could be undefined by the end of thematch x
statement.Actual Behavior
mypy --enable-error-code=possibly-undefined repro.py
produces this output, which seems like a false positive:What's particularly strange, however, is that adding
--warn-unreachable
makes the error go away:It seems like there's two bugs here:
possibly-undefined
error is a false positive--warn-unreachable
to the config reduces the number ofpossibly-undefined
errors emitted by mypy, and it seems like it definitely shouldn't be doing that.Cc. @ilinum for
possibly-undefined
expertise :)Your Environment
The text was updated successfully, but these errors were encountered: