-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
used-before-assignment
false negative after conditionals
#1727
Comments
Just here to second this. |
Ran into this at work today! |
Do we want to create a new checker called |
Did you mean "possibly-used-before-assignment" ? |
Yeah 😅 |
I think it makes sense. Adding a good control flow to astroid would be nice but is also difficult. |
This kind of problem would be avoided entirely if the variable were set with a ternary expression! |
used-before-assignment
false negative after conditionals
@jacobtylerwalls I think you wanted to post this message in another issue because this one is #1727 :D |
Thanks, I fixed the numbers in my comment. :-) |
@jacobtylerwalls @Pierre-Sassoulas - i would like to help implement this, |
Very cool! I'd familiarize yourself with this method and how it is used, focusing on the three return statements at the end: pylint/pylint/checkers/variables.py Lines 687 to 690 in 7eaac57
Essentially, thanks to hard work by @zenlyj, we have a pretty clean interface for emitting used-before-assignment or not based on whether or not we care about a certain if/else pattern. We've been ratcheting up the messages slowly. First we just started emitting used-before-assignment only when we can tell that all possible values of the test are False (and therefore the if is always skipped). So, this issue is about being even bolder, and emitting something (either used-before-assignment or a new message possibly-used-before-assignment) regardless of the inferred possible values of the test (see the It might be nice to get a draft PR going without defining a separate message just to see how noisy it would be. Then we can evaluate whether to create a second message for it. Does that make sense? |
Ah -- I'm thinking we shouldn't have a second message type, as it would blur the boundary between message type and confidence. We should just be really specific about the confidence, including using |
Thank you for your interest in this issue :) Jacob worked a lot on it and is definitely the code owner on this message, I agree with what was said do not hesitate to open a draft PR and use primers in our CI as a dev tool. |
Running pylint on this simple example does not detect that x can be used before assignment. This is a very common programming mistake and should be caught.
Current behavior - Fails to detect x is used before assignment
Expected behavior: detect variable use inside logic branches.
pylint --version output: pylint-2 1.7.4
The text was updated successfully, but these errors were encountered: