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

gh-151428: Remove unused imports from stdlib#151478
hugovk merged 3 commits into
python:mainfrom
hugovk:3.16-rm-unused-imports

Conversation

@hugovk

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

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

johnslavik 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

@AlexWaygoodAlexWaygood 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 threadTools/.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)

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...?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Sure, updated.

Comment threadTools/.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

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 :-)

Copy link
Copy Markdown
MemberAuthor

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 threadLib/.ruff.toml

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

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

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

And for this.

@pablogsal

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 😉

@vstinnervstinner 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 threadTools/.ruff.toml
[lint]
select = [
"F401", # Unused import
]

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?

Copy link
Copy Markdown
MemberAuthor

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.)

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:mainJun 16, 2026
57 checks passed
@hugovk
hugovk deleted the 3.16-rm-unused-imports branch June 16, 2026 16:31
philthompson10 pushed a commit to philthompson10/cpython that referenced this pull request Jun 17, 2026
@bedevere-app

Copy link
Copy Markdown

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

terryjreedy added a commit that referenced this pull request Jul 2, 2026
…) (GH-152916) (#152918)
[3.15] gh-151428: Remove unused imports in idlelib.idle_test (GH-151478) (GH-152916)
(cherry picked from commit 984ebbf)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
terryjreedy added a commit that referenced this pull request Jul 2, 2026
…) (GH-152916) (#152917)
[3.15] gh-151428: Remove unused imports in idlelib.idle_test (GH-151478) (GH-152916)
(cherry picked from commit 984ebbf)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@hugovk@johnslavik@pablogsal@vstinner@AlexWaygood@StanFromIreland