[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.
This commit is contained in:
GiGaGon 2025-07-04 11:38:37 -07:00 committed by GitHub
parent 411cccb35e
commit f48a34fbab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 11 deletions

View file

@ -24,13 +24,14 @@ use crate::checkers::ast::Checker;
/// ## Example /// ## Example
/// ```python /// ```python
/// with open("file", "rwx") as f: /// with open("file", "rwx") as f:
/// return f.read() /// content = f.read()
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
///
/// ```python /// ```python
/// with open("file", "r") as f: /// with open("file", "r") as f:
/// return f.read() /// content = f.read()
/// ``` /// ```
/// ///
/// ## References /// ## References

View file

@ -15,21 +15,23 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ///
/// ## Example /// ## Example
/// ```python /// ```python
/// for x in foo: /// def bar():
/// yield x /// for x in foo:
/// yield x
/// ///
/// global y /// global y
/// for y in foo: /// for y in foo:
/// yield y /// yield y
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```python /// ```python
/// yield from foo /// def bar():
/// yield from foo
/// ///
/// for _element in foo: /// for _element in foo:
/// y = _element /// y = _element
/// yield y /// yield y
/// ``` /// ```
/// ///
/// ## Fix safety /// ## Fix safety