forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flake8-bugbear] Catch yield in subexpressions (B901) (astral-sh#14453)
Currently, the B901 rule misses yield expressions that are not top-of-tree, for example as in def f(): x = yield print(x) return 42 This commit refactors the rule to find such yield expressions. Assignments are traversed and identifiers bound to yield or yield from expressions are tracked, so that if the value bound to those identifiers are later returned (which is valid), the rule is not triggered. The assignment traversal part is inspired by the match_value and match_target functions from src/analyze/typing.rs in the ruff_python_semantic crate. The relevant issue is astral-sh#14453.
- Loading branch information
Showing
3 changed files
with
264 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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