Commits
Click on a commit to change the comparison range[flake8-bugbear] Catch yield in subexpressions (B901) (#14453)
Currently, the B901 rule misses yield expressions that are not
top-of-tree in a function body, 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 a value bound to
those identifiers is 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 #14453. Refactor to account for subexpressions otherwise following bugbear Merge branch 'main' into refactor/b901_missing_yield_subexpressions Add comment for skipping assignments