Repository navigation
[flake8-bugbear] Fix panic on match subjects (B031) - #27781
Merged
Merged
Conversation
…ect (B031) The `Stmt::Match` arm pushed an empty branch-counter frame before visiting the subject, so a group usage in the subject unwrapped `last_mut()` on the empty frame and panicked. Visit the subject first: it is evaluated unconditionally, so it belongs to the enclosing count, and a subsequent usage in a case body is still flagged. Fixes astral-sh#26624
pikammmmm
force-pushed
the
fix-b031-match-subject-panic
branch
from
August 15, 2026 19:07
cc25d72 to
b546bb4
Compare
|
ntBre
reviewed
Aug 17, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
Thanks, this looks good to me overall. I just had one suggestion to treat If statements similarly and a small nit about a comment.
The comment on the `match` subject fix referenced a panic that no longer exists after the fix; trim it to the first sentence per review feedback. Also extend the same "visit unconditionally-evaluated expression before pushing branch counters" pattern to `if` statement tests, which are evaluated unconditionally just like a `match` subject. Previously the test's usage was attributed to the `if` branch's counter, causing a false negative when the group was reused in the `else` branch (or another elif branch).
Contributor
Author
|
Trimmed the comment to the first sentence, and extended the unconditional-visit-then-track-counters pattern to |
flake8-bugbear] Fix B031 panic on match subjectsflake8-bugbear] Fix panic on match subjects (B031)
ntBre
enabled auto-merge (squash)
August 28, 2026 20:56
|
Thanks! |
1 task
1 task
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.


Fixes #26624