Fix false positive in for mutations in return statements (B909)#18408
Merged
ntBre merged 3 commits intoastral-sh:mainfrom Jun 13, 2025
Merged
Fix false positive in for mutations in return statements (B909)#18408ntBre merged 3 commits intoastral-sh:mainfrom
ntBre merged 3 commits intoastral-sh:mainfrom
Conversation
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PYI059 | 26 | 0 | 0 | 26 | 0 |
| B909 | 1 | 0 | 1 | 0 | 0 |
ntBre
reviewed
Jun 3, 2025
Contributor
ntBre
left a comment
There was a problem hiding this comment.
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
ntBre
reviewed
Jun 4, 2025
crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs
Outdated
Show resolved
Hide resolved
Contributor
Author
|
@ntBre |
ntBre
approved these changes
Jun 13, 2025
Contributor
ntBre
left a comment
There was a problem hiding this comment.
Excellent, thank you! It's always fun to fix a bug by deleting code :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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