Skip to content

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

Merged
ntBre merged 3 commits into
astral-sh:mainfrom
trilamsr:up029-doc-clarify-21148
Jun 23, 2026
Merged

ntBre merged 3 commits into
astral-sh:mainfrom
trilamsr:up029-doc-clarify-21148

Conversation

@trilamsr

Copy link
Copy Markdown
Contributor

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.

…#21148)

The existing docs describe UP029 as catching unnecessary builtin imports
in general, but the rule only fires on a fixed set of Python 2 / Python 3
compatibility imports (from `builtins`, `io.open`, `six`, and `six.moves`).
Reword "What it does" and "Why is this bad?" to match. The violation
message and rule logic are unchanged.

Closes astral-sh#21148.

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks good overall, just one clarification on the source of builtins and io, as I understand it.

Comment thread crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs Outdated
@ntBre ntBre added the documentation Improvements or additions to public-facing documentation label Jun 22, 2026
@ntBre ntBre changed the title [ruff] Clarify UP029 docs as a Python 2 compatibility rule [pyupgrade] Clarify UP029 as a Python 2 compatibility rule Jun 22, 2026
@trilamsr

trilamsr commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Good catch, thanks! You're right. Verified that from builtins import str only resolves to a real shim when python-future is installed; stdlib builtins is a completely different package. Pushed your suggestion.

@astral-sh-bot

astral-sh-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ntBre
ntBre enabled auto-merge (squash) June 23, 2026 15:21
@ntBre
ntBre merged commit a4bfeb1 into astral-sh:main Jun 23, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to public-facing documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unnecessary-builtin-import (UP029)’s documentation does not match its implementation

2 participants