[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
/// ```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

View file

@ -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