[pyupgrade] Clarify UP029 as a Python 2 compatibility rule (#26243)

Hi! Small intro contribution to ruff #21148.

The current UP029 docs read like the rule catches any import of a
builtin (e.g. `from builtins import tuple`), but the rule only fires on
a fixed allowlist of Python 2 / Python 3 compatibility imports from
`builtins`, `io.open`, `six`, and `six.moves`. The issue reporter
pointed this out and matches what the upstream pyupgrade rule was
originally designed for.

Scope is just the `## What it does` and `## Why is this bad?` doc
comments. Violation message, example, fix, and rule logic are untouched,
so no snapshots move.

Hand-wrote the PR summary per the AI policy.

Closes #21148.
This commit is contained in:
Tri Lam authored and GitHub committed 2026-06-23 15:25:51 +00:00
1 parent 3e46953719
commit a4bfeb12f9
1 file changed
+4 -3
@@ -10,11 +10,12 @@ use crate::rules::pyupgrade::rules::is_import_required_by_isort;
use crate::{AlwaysFixableViolation, Fix};
/// ## What it does
/// Checks for unnecessary imports of builtins.
/// Checks for imports of Python 3 builtins from Python 2 compatibility shims
/// such as `python-future` and `six`.
///
/// ## Why is this bad?
/// Builtins are always available. Importing them is unnecessary and should be
/// removed to avoid confusion.
/// These shims existed to access Python 3 builtins from code that also ran on
/// Python 2. On Python 3-only code, the imports are redundant.
///
/// ## Example
/// ```python