← 输入框|github.com|刷新
Skip to content

gh-151428: Remove unused imports from stdlib - #151478

Merged
hugovk merged 3 commits into
python:mainfrom
hugovk:3.16-rm-unused-imports
Jun 16, 2026
Merged

hugovk merged 3 commits into
python:mainfrom
hugovk:3.16-rm-unused-imports

Conversation

@hugovk

@hugovk hugovk commented Jun 14, 2026 •

Copy link
Copy Markdown
Member

Follow on from #151440 and #151442.

Also add Ruff F401 to help avoid this in the future, and exclude any files with false positives (rather than adding noqa comments).

Comment thread .pre-commit-config.yaml

ghost left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Pablo might need to update his "Attracts linker errors" line to "Attracts linker errors and unused imports," I think I see a pattern in the affected files ;-)

@johnslavik

ghost commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Pablo might need to update his "Attracts linker errors" line to "Attracts linker errors and unused imports," I think I see a pattern in the affected files ;-)

Attracts lin[kt]er errors

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(I only reviewed the changes to the config files)

Comment thread Tools/.ruff.toml Outdated
Comment on lines +3 to +4
[per-file-target-version]
"jit/example_trace_dump.py" = "py312" # Reused-quote f-strings (PEP 701)

ghost Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should this be the target version for the whole jit directory, rather than just one file...?

ghost Jun 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, updated.

Comment thread Tools/.ruff.toml
Comment on lines +11 to +14
[lint.per-file-ignores]
"c-analyzer/c_parser/__init__.py" = ["F401"] # Re-exports from submodules
"c-analyzer/c_parser/preprocessor/__init__.py" = ["F401"] # Re-exports from submodules
"c-analyzer/c_parser/preprocessor/common.py" = ["F401"] # Re-exported by preprocessor/__init__.py

ghost Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Adding __all__ and listing the re-exports in __all__ would probably be a more idiomatic way of fixing these errors (but perhaps that's something for a followup PR, since there's a chance it could be controversial :-)

ghost Jun 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will open a followup for this.

Comment thread Lib/.ruff.toml

[lint.per-file-ignores]
"ctypes/__init__.py" = ["F401"] # Re-exports from _ctypes
"ensurepip/__init__.py" = ["F401"] # `import zlib` availability check

ghost Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in a case like this where there's only one error, I'd usually lean towards using a noqa comment in the code rather than per-file-ignores. But, again, perhaps that's best done as a followup..

ghost Jun 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

And for this.

@pablogsal

ghost commented Jun 15, 2026

Copy link
Copy Markdown
Member

LGTM

Pablo might need to update his "Attracts linker errors" line to "Attracts linker errors and unused imports," I think I see a pattern in the affected files ;-)

Keeping those linters busy man 😉

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread Tools/.ruff.toml
[lint]
select = [
"F401", # Unused import
]

ghost Jun 16, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it needed to repeat it? It's already in the parent (project) configuration, no?

ghost Jun 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The parent config doesn't define a select, so defaults to ["E4", "E7", "E9", "F"].

We don't want to run the whole F category, or those other ones, so this select overwrites that one.

(There is an extend-select that is in addition to select, but we do want a smaller set here.)

ghost Jun 16, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh sorry, I mixed Lib/.ruff.toml and .ruff.toml. You're right.

@hugovk
hugovk merged commit 627adb5 into python:main Jun 16, 2026
@hugovk
hugovk deleted the 3.16-rm-unused-imports branch June 16, 2026 16:31
@bedevere-app

ghost commented Jul 2, 2026

Copy link
Copy Markdown

GH-152916 is a backport of this pull request to the 3.15 branch.

Comment thread Lib/idlelib/idle_test/template.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants