-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Detect exhaustiveness in partially-defined variable checks #13926
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
Comments
@JukkaL (or anyone else), I would appreciate some help here because I'm a bit stuck. I have discovered has two places where it finds unreachable code:
Semantic Analyzer marks blocks with Logic using conditional type binder: Line 459 in 3c5f368
What I would like to do is to store information about unreachable blocks somewhere. My original approach, was to set def f1(x: int | str) -> int:
if isinstance(x, int):
y = 1
elif isinstance(x, str):
y = 2
else:
pass
return y # No error any more. However, this only works if there is a body but not if the body is missing (so the original examples here don't work). We can add special fields to the Can you think of a good way of storing branch reachability information somewhere? |
Nothing comes to mind immediately, but I'll think about this more tomorrow. |
This adds support for unreachable blocks in `partially-defined` check. Currently, this only supports blocks that are detected as unreachable during semantic analysis (so mostly stuff like python version, etc.). This doesn't support more advanced cases (see #13926 for an example what's not covered). Closes #13929
@JukkaL would appreciate some pointers here if you have a bit of time! :) |
Sorry, lost track of this. I'll think about this next week (keep pinging me if you don't hear anything by mid next week). |
@ilinum I think reusing For example, if |
Was the "partially-defined" error code ever implemented? I don't see any reference to it in the mypy docs or sources. I'm not able to repro the error with the code sample, but perhaps I'm not configuring mypy correctly. Or maybe this issue has been fixed. |
yes, but the name was changed to |
For the partially defined check (
--enable-error-code partially-defined
), mypy generates a false-positive in the following case:The same applies to
match
statements:It's likely that mypy already detects this somewhere, since it doesn't complain about the missing return:
The text was updated successfully, but these errors were encountered: