ruff
beda1575 - [`ruff`] Add `unnecessary-assign-before-yield` (`RUF070`) (#23300)

Commit
100 days ago
[`ruff`] Add `unnecessary-assign-before-yield` (`RUF070`) (#23300) ## Summary Closes #13141 Adds a new rule `unnecessary-assign-before-yield` (`RUF070`) that detects variable assignments immediately followed by a `yield` (or `yield from`) of that variable, where the variable is not referenced anywhere else. This is the `yield` equivalent of `RET504` (`unnecessary-assign`). ```python # Before def gen(): x = 1 yield x # After def gen(): yield 1 ``` Unlike return, yield does not exit the function, so the rule only triggers when the binding has exactly one reference (the yielditself). The fix is marked as unsafe for the same reason. ## Test Plan cargo nextest run -p ruff_linter -- RUF070 --------- Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
Parents
Loading