Skip to content

Commit f48a34f

Browse files
authored
[pylint, pyupgrade] Fix syntax errors in examples (PLW1501, UP028) (#19127)
## Summary From me and @ntBre's discussion in #19111. This PR makes these two examples into valid code, since they previously had `F701`-`F707` syntax errors. `SIM110` was already fixed in a different PR, I just forgot to pull.
1 parent 411cccb commit f48a34f

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ use crate::checkers::ast::Checker;
2424
/// ## Example
2525
/// ```python
2626
/// with open("file", "rwx") as f:
27-
/// return f.read()
27+
/// content = f.read()
2828
/// ```
2929
///
3030
/// Use instead:
31+
///
3132
/// ```python
3233
/// with open("file", "r") as f:
33-
/// return f.read()
34+
/// content = f.read()
3435
/// ```
3536
///
3637
/// ## References

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ use crate::{Edit, Fix, FixAvailability, Violation};
1515
///
1616
/// ## Example
1717
/// ```python
18-
/// for x in foo:
19-
/// yield x
18+
/// def bar():
19+
/// for x in foo:
20+
/// yield x
2021
///
21-
/// global y
22-
/// for y in foo:
23-
/// yield y
22+
/// global y
23+
/// for y in foo:
24+
/// yield y
2425
/// ```
2526
///
2627
/// Use instead:
2728
/// ```python
28-
/// yield from foo
29+
/// def bar():
30+
/// yield from foo
2931
///
30-
/// for _element in foo:
31-
/// y = _element
32-
/// yield y
32+
/// for _element in foo:
33+
/// y = _element
34+
/// yield y
3335
/// ```
3436
///
3537
/// ## Fix safety

0 commit comments

Comments
 (0)