From f48a34fbab08809526cc1c73db8ca0541844d0fa Mon Sep 17 00:00:00 2001 From: GiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Fri, 4 Jul 2025 11:38:37 -0700 Subject: [PATCH] [`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. --- .../src/rules/pylint/rules/bad_open_mode.rs | 5 +++-- .../pyupgrade/rules/yield_in_for_loop.rs | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs index 0427bab652..b89cbf1425 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs @@ -24,13 +24,14 @@ use crate::checkers::ast::Checker; /// ## Example /// ```python /// with open("file", "rwx") as f: -/// return f.read() +/// content = f.read() /// ``` /// /// Use instead: +/// /// ```python /// with open("file", "r") as f: -/// return f.read() +/// content = f.read() /// ``` /// /// ## References diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs index e7f88cd553..8fa6118e4c 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs @@ -15,21 +15,23 @@ use crate::{Edit, Fix, FixAvailability, Violation}; /// /// ## Example /// ```python -/// for x in foo: -/// yield x +/// def bar(): +/// for x in foo: +/// yield x /// -/// global y -/// for y in foo: -/// yield y +/// global y +/// for y in foo: +/// yield y /// ``` /// /// Use instead: /// ```python -/// yield from foo +/// def bar(): +/// yield from foo /// -/// for _element in foo: -/// y = _element -/// yield y +/// for _element in foo: +/// y = _element +/// yield y /// ``` /// /// ## Fix safety