-
-
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
Fix used-before-assignment
false positive for walrus operators in ifs
#8029
Fix used-before-assignment
false positive for walrus operators in ifs
#8029
Conversation
used-before-assignment
false positive
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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 a simplification with early return ?
@zenlyj the changelog file is required. There are a number here if you need to check how that is done |
β¦lint into bug-used-before-assign
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
@zenlyj The Python 3.7 test in the CI is failing because Walrus is a syntax-error. It's possible to run this test for Python versions greater than 3.7. There are many examples in the existing functional tests where a |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8029 +/- ##
=======================================
Coverage 95.42% 95.42%
=======================================
Files 176 176
Lines 18525 18527 +2
=======================================
+ Hits 17678 17680 +2
Misses 847 847
|
@mbyrnepr2 Thank you for helping with the CI fails, very helpful advice. |
π€ According to the primer, this change has no effect on the checked open source code. π€π This comment was generated for commit cad42be |
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 for the fix, the test cases are pretty nice too. This will be available in 2.15.10 :)
used-before-assignment
false positiveused-before-assignment
false positive for walrus operators in ifs
β¦fs (#8029) Co-authored-by: Pierre Sassoulas <[email protected]> (cherry picked from commit 6ac908f)
β¦fs (#8029) (#8033) Co-authored-by: Pierre Sassoulas <[email protected]> (cherry picked from commit 6ac908f) Co-authored-by: Zen Lee <[email protected]>
Type of Changes
Description
After investigation, there seems to be two main cases that trigger used-before-assignment false positives:
(foo if (foo:='foo') else 'bar').upper()
str(str(foo if (foo:='foo') else 'bar'))
This fix enforces a stricter check on whether a name may be assigned and used in the same statement.
Closes #7779