-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix false positive in for mutations in return statements (B909) #18408
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 false positive in for mutations in return statements (B909) #18408
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PYI059 | 26 | 0 | 0 | 26 | 0 |
| B909 | 1 | 0 | 1 | 0 | 0 |
ntBre
left a comment
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.
Thanks! The new tests look great, but I think there might be a simpler fix for the issue.
crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs
Outdated
Show resolved
Hide resolved
|
@ntBre |
ntBre
left a comment
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.
Excellent, thank you! It's always fun to fix a bug by deleting code :)
Summary
Fixes false positive in B909 (
loop-iterator-mutation) where mutations inside return/break statements were incorrectly flagged as violations.The fix adds tracking for when mutations occur within return/break statements and excludes them from violation detection, as they don't cause the iteration issues B909 is designed to prevent.
Test Plan
B909.pycargo test -p ruff_linter --lib flake8_bugbearsuccessfullyFixes #18399