Skip to content

Commit

Permalink
Add fix safety note for yield-in-for-loop (#9364)
Browse files Browse the repository at this point in the history
See: #8482.
  • Loading branch information
charliermarsh authored Jan 2, 2024
1 parent 2743387 commit f07d350
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ use crate::checkers::ast::Checker;
/// yield from foo
/// ```
///
/// ## Fix safety
/// This rule's fix is marked as unsafe, as converting a `for` loop to a `yield
/// from` expression can change the behavior of the program in rare cases.
/// For example, if a generator is being sent values via `send`, then rewriting
/// to a `yield from` could lead to an attribute error if the underlying
/// generator does not implement the `send` method.
///
/// In most cases, however, the fix is safe, and such a modification should have
/// no effect on the behavior of the program.
///
/// ## References
/// - [Python documentation: The `yield` statement](https://docs.python.org/3/reference/simple_stmts.html#the-yield-statement)
/// - [PEP 380](https://peps.python.org/pep-0380/)
Expand Down

0 comments on commit f07d350

Please sign in to comment.