"Statement is unreachable" when doing match
on type
objects
#18524
Labels
bug
mypy got something wrong
topic-match-statement
Python 3.10's match statement
topic-reachability
Detecting unreachable code
Hello mypy maintainers! I attempted to search for a dupe for this but couldn't find one, apologies if I missed it.
Bug Report
When running
mypy
withwarn_unreachable = true
(set in pyproject, but also on CLI), I get what appears to be a false positive for unreachable code onmatch
statements where the matched object is atype
and some of the arms are types.For example (minimized/abstracted from my actual code):
Produces:
However, at runtime, I can confirm that these
case
arms are matched correctly.To Reproduce
Playground reproducer: https://mypy-play.net/?mypy=latest&python=3.13&flags=warn-unreachable&gist=416b0d53cd61032acee0341e9b24de11
(Note that
--warn-unreachable
needs to be enabled for reproduction. I think the Playground link should preserve this, but just in case!)Expected Behavior
I expected
mypy
to match ontype
objects correctly, as Python itself appears to do correctly at runtime.Actual Behavior
From above:
Your Environment
--warn-unreachable
mypy.ini
(and other config files): N/AThe text was updated successfully, but these errors were encountered: