-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent crashing when match
arms use name of existing callable
#18449
Prevent crashing when match
arms use name of existing callable
#18449
Conversation
… match as non-Vars
This comment has been minimized.
This comment has been minimized.
I have a trivial fix for the rest of #13666 (reachability issue, |
mypy/checker.py
Outdated
if type_map: | ||
for expr, typ in list(type_map.items()): | ||
if isinstance(expr, NameExpr): | ||
node = expr.node | ||
assert isinstance(node, Var) | ||
if node not in inferred_types or not is_subtype(typ, inferred_types[node]): | ||
if isinstance(node, Var) and ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(maybe silly q, not too familiar with this code) why do we need to do this only if node is a Var?
Diff from mypy_primer, showing the effect of this PR on open source code: schemathesis (https://github.com/schemathesis/schemathesis)
- File "/tmp/mypy_primer/old_mypy/venv/bin/mypy", line 8, in <module>
+ File "/tmp/mypy_primer/new_mypy/venv/bin/mypy", line 8, in <module>
- File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/__main__.py", line 15, in console_entry
+ File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/__main__.py", line 15, in console_entry
- File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/main.py", line 119, in main
+ File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/main.py", line 119, in main
- File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/main.py", line 203, in run_build
+ File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/main.py", line 203, in run_build
- File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 191, in build
+ File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 191, in build
- File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 267, in _build
+ File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 267, in _build
- File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 2947, in dispatch
+ File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 2947, in dispatch
- File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 976, in write_deps_cache
+ File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 976, in write_deps_cache
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you and thanks also for the additional tests!
Fixes #16793. Fixes crash in #13666.
Previously mypy considered that variables in match/case patterns must be Var's, causing a hard crash when a name of captured pattern clashes with a name of some existing function. This PR removes such assumption about Var and allows other nodes.