Repository navigation
B909: visit if conditions and alternate branches - #606
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused traversal fix has targeted regression coverage and no unresolved review findings.
No open issues 🎉
What changed in this PR
This PR fixes missed B909 diagnostics by extending the mutation checker to visit if conditions and alternate branches.
Changes:
- Visit conditions and
elif/elsebranches while keeping alternate mutation blocks separate. - Add regression cases for these paths and unconditional versus conditional
breakbehavior.
| File | Description |
|---|---|
tests/eval_files/b909.py |
Adds regression coverage for conditions, alternate branches, and break handling. |
bugbear.py |
Extends B909’s if traversal while preserving separate mutation blocks. |
Review effort: Balanced
cooperlees
approved these changes
Oct 24, 2026
cooperlees
left a comment
Collaborator
There was a problem hiding this comment.
Many thanks for this! Good enchancement
@copilot Can you add a CHANGE LOG entry for this?
Collaborator
|
@copilot Can you add a change log entry for this on to the PR in a new commit please. |
cooperlees
added a commit
to Don-Yin/flake8-bugbear
that referenced
this pull request
Oct 24, 2026
Visit the test and orelse nodes while keeping conditional mutation blocks separate, preserving the existing handling of unconditional breaks. Signed-off-by: Don Yin <Don_Yin@outlook.com>
cooperlees
force-pushed
the
fix-b909-if-branches
branch
from
October 24, 2026 20:16
cd245d4 to
8a37d0b
Compare
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.
B909 currently visits only the body of an
if, so mutations in its condition orelif/elsebranches go unnoticed. For example:flake8 --isolated --select=B909 example.pyreports nothing on main; with this change it reports the mutation on line 6.This adds the missing visits and keeps alternate branches in separate mutation blocks, preserving the existing handling of unconditional
break. The existing B909 fixture now coverselif,else, a mutating condition, and unconditional/conditional break controls.Validation:
pep8_namingpass. Python 3.15 was not available locally.pre-commit run --all-filespasses (isort, Black, flake8, rstcheck).py313-mypyreports the same seven errors on pristine basebc1ec773c4bcaf121ca810cb78f5fcb3249d88c9and this branch.Measured B909 counts for six small snippets, including unchanged controls (inputs and diagnostic output):