Skip to content

Commit f07d350

Browse files
Add fix safety note for yield-in-for-loop (#9364)
See: #8482.
1 parent 2743387 commit f07d350

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ use crate::checkers::ast::Checker;
2424
/// yield from foo
2525
/// ```
2626
///
27+
/// ## Fix safety
28+
/// This rule's fix is marked as unsafe, as converting a `for` loop to a `yield
29+
/// from` expression can change the behavior of the program in rare cases.
30+
/// For example, if a generator is being sent values via `send`, then rewriting
31+
/// to a `yield from` could lead to an attribute error if the underlying
32+
/// generator does not implement the `send` method.
33+
///
34+
/// In most cases, however, the fix is safe, and such a modification should have
35+
/// no effect on the behavior of the program.
36+
///
2737
/// ## References
2838
/// - [Python documentation: The `yield` statement](https://docs.python.org/3/reference/simple_stmts.html#the-yield-statement)
2939
/// - [PEP 380](https://peps.python.org/pep-0380/)

0 commit comments

Comments
 (0)