Structural Pattern Matching False Positive With Nested Data Structures #12770
Labels
bug
mypy got something wrong
topic-match-statement
Python 3.10's match statement
topic-reachability
Detecting unreachable code
Bug Report
mypy underestimates the reachability of case blocks matching
Any
(or data structures containingAny
) against nested data structures. This particularly impacts the use of structural pattern matching to parse JSON and other data formats that frequently include recursive data structures. It's difficult to avoid usingAny
for some portion of the type in these cases, so for now I believe the best workaround in these cases is to setwarn_unreachable
tofalse
or suppress the mypy errors on the pertinent lines.To Reproduce
Create a
test.py
file with the following contents:Run
mypy test.py
withwarn_unreachable
set totrue
.Expected Behavior
I expected all lines to be considered reachable since
x
may be{"y": [0]}
, for instance.Actual Behavior
Your Environment
Mypy version used: mypy 0.960+dev.8faf44ad44f19c2dcf3f31f12eed5e58494fc3a3
Mypy command-line flags: None
Mypy configuration options from
mypy.ini
(and other config files):In
pyproject.toml
:Python version used: 3.10.4
The text was updated successfully, but these errors were encountered: