B901 catches yields in subexprs and more sensitive B901#15101
Closed
guptaarnav wants to merge 1 commit intoastral-sh:mainfrom
Closed
B901 catches yields in subexprs and more sensitive B901#15101guptaarnav wants to merge 1 commit intoastral-sh:mainfrom
guptaarnav wants to merge 1 commit intoastral-sh:mainfrom
Conversation
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| B901 | 32 | 32 | 0 | 0 | 0 |
Contributor
Author
|
Saw a large number of violations from the automated ruff-ecosystem check. primarily seems to be from code that says |
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
Closes #14453 by updating the implementation of the B901 lint rule. The changes ensure that:
1. The visitor now traverses all expressions within statements, ensuring yield expressions embedded are correctly flagged even if they are not the expression of an
ExprStmt.2. The rule now correctly identifies yield and yield from expressions when they appear as the right-hand side of assignment statements (e.g., x = yield or x = yield from []); this catches the case mentioned in the original issue by @AlexWaygood.
3. We still do not recurse into lambda expressions or nested function defs as these are evaluated separately.
Test Plan
I added the tests mentioned by @MichaReiser and @AlexWaygood in the original issue into
test/fixtures/flake8_bugbear/B901.pyand updated the related snapshot.