]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151428: Remove unused imports from stdlib (#151478)
authorHugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Tue, 16 Jun 2026 16:31:01 +0000 (19:31 +0300)
committerGitHub <noreply@github.com>
Tue, 16 Jun 2026 16:31:01 +0000 (19:31 +0300)
13 files changed:
.pre-commit-config.yaml
Lib/.ruff.toml [new file with mode: 0644]
Lib/_pyrepl/completing_reader.py
Lib/_pyrepl/reader.py
Lib/_pyrepl/unix_console.py
Lib/idlelib/idle_test/template.py
Lib/idlelib/idle_test/test_help.py
Lib/profiling/sampling/heatmap_collector.py
Lib/profiling/sampling/live_collector/collector.py
Lib/profiling/sampling/live_collector/display.py
Lib/profiling/sampling/live_collector/widgets.py
Lib/profiling/sampling/sample.py
Tools/.ruff.toml [new file with mode: 0644]

index 6878a7d92e3beeb00d5dfc1c0c3e37c962a6e336..6c7f1b93e66e879aa85a65a62583bbaba10c42c8 100644 (file)
@@ -1,6 +1,6 @@
 repos:
   - repo: https://github.com/astral-sh/ruff-pre-commit
-    rev: e05c5c0818279e5ac248ac9e954431ba58865e61  # frozen: v0.15.7
+    rev: 3b3f7c3f57fe9925356faf5fe6230835138be230  # frozen: v0.15.17
     hooks:
       - id: ruff-check
         name: Run Ruff (lint) on Platforms/Apple/
@@ -10,6 +10,11 @@ repos:
         name: Run Ruff (lint) on Doc/
         args: [--exit-non-zero-on-fix]
         files: ^Doc/
+      - id: ruff-check
+        name: Run Ruff (lint) on Lib/
+        args: [--exit-non-zero-on-fix]
+        files: ^Lib/
+        exclude: ^Lib/test/
       - id: ruff-check
         name: Run Ruff (lint) on Lib/test/
         args: [--exit-non-zero-on-fix]
@@ -18,6 +23,11 @@ repos:
         name: Run Ruff (lint) on Platforms/WASI/
         args: [--exit-non-zero-on-fix, --config=Platforms/WASI/.ruff.toml]
         files: ^Platforms/WASI/
+      - id: ruff-check
+        name: Run Ruff (lint) on Tools/
+        args: [--exit-non-zero-on-fix]
+        files: ^Tools/
+        exclude: ^Tools/(build|clinic|i18n|peg_generator|wasm)/
       - id: ruff-check
         name: Run Ruff (lint) on Tools/build/
         args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
diff --git a/Lib/.ruff.toml b/Lib/.ruff.toml
new file mode 100644 (file)
index 0000000..c9ae9b9
--- /dev/null
@@ -0,0 +1,21 @@
+extend = "../.ruff.toml"  # Inherit the project-wide settings
+
+# Unlike Tools/, stdlib can use newer syntax than PYTHON_FOR_REGEN
+target-version = "py315"
+
+[lint]
+select = [
+    "F401",  # Unused import
+]
+
+[lint.per-file-ignores]
+"ctypes/__init__.py" = ["F401"]  # Re-exports from _ctypes
+"ensurepip/__init__.py" = ["F401"]  # `import zlib` availability check
+"idlelib/idle_test/htest.py" = ["F401"]  # Import for Windows DPI side effect
+"idlelib/idle_test/test_iomenu.py" = ["F401"]  # Imports checked for existence
+"importlib/_abc.py" = ["F401"]  # Bootstrap-sensitive _bootstrap import
+"importlib/machinery.py" = ["F401"]  # NamespacePath re-export
+"importlib/metadata/__init__.py" = ["F401"]  # Synced from importlib_metadata
+"profiling/sampling/sample.py" = ["F401"]  # Re-exports PROFILING_MODE_* constants
+"ssl.py" = ["F401"]  # Re-exports from _ssl
+"warnings.py" = ["F401"]  # Re-exports from _py_warnings
index f783e8db36b02877b0a96c7e79a63e604c486214..7eb3ebac84124b5cafba7b30ebbc769318f392b7 100644 (file)
@@ -32,7 +32,7 @@ from .reader import Reader
 # types
 Command = commands.Command
 if TYPE_CHECKING:
-    from .types import CommandName, CompletionAction, Keymap, KeySpec
+    from .types import CompletionAction, Keymap
 
 
 def prefix(wordlist: list[str], j: int = 0) -> str:
index 7e4dd801c84d5c249d01c689a1f44c4fc5804a8b..832e67b534f296941cc939835fb29d66398da77d 100644 (file)
@@ -38,7 +38,7 @@ from .content import (
 )
 from .layout import LayoutMap, LayoutResult, LayoutRow, WrappedRow, layout_content_lines
 from .render import RenderCell, RenderLine, RenderedScreen, ScreenOverlay
-from .utils import ANSI_ESCAPE_SEQUENCE, ColorSpan, THEME, StyleRef, wlen, gen_colors
+from .utils import ANSI_ESCAPE_SEQUENCE, ColorSpan, THEME, StyleRef, gen_colors
 from .trace import trace
 
 
index 9c4644db53e3436a3a4bf455a892a022c2a13e6b..9a4f8e0c623abfa6daee6836516087e80a448007 100644 (file)
@@ -34,7 +34,7 @@ import platform
 from collections.abc import Callable
 from dataclasses import dataclass
 from fcntl import ioctl
-from typing import TYPE_CHECKING, cast, overload
+from typing import TYPE_CHECKING, overload
 
 from . import terminfo
 from .console import Console, Event
index 725a55b9c47230c32c63b3e6cd036f0319173046..6e98556458ec588f94ac8813ab610fd742b8a9a9 100644 (file)
@@ -1,6 +1,5 @@
 "Test , coverage %."
 
-from idlelib import zzdummy
 import unittest
 from test.support import requires
 from tkinter import Tk
index ebb02b5c0d8356a89c70acc64de226064ef7e63d..ebbaceb2eb7bbfdfefa925ffe70f59b3a8845daa 100644 (file)
@@ -4,7 +4,6 @@ from idlelib import help
 import unittest
 from test.support import requires
 requires('gui')
-from os.path import abspath, dirname, join
 from tkinter import Tk
 
 
index 6e650ec08f410bc76ae844a11f5c6cc231b2593d..78f1e39f6a002d0cf4ad1fe0b1129e6ad3fd759d 100644 (file)
@@ -5,11 +5,9 @@ import collections
 import html
 import importlib.resources
 import json
-import locale
 import math
 import os
 import platform
-import site
 import sys
 from dataclasses import dataclass, field
 from pathlib import Path
index a53cfc6b719a105ef9b464cfcd23d6d03ceb0773..2805134f239eb38eb57cfeeec0e9620761c77f9e 100644 (file)
@@ -18,9 +18,6 @@ from ..constants import (
     THREAD_STATUS_UNKNOWN,
     THREAD_STATUS_GIL_REQUESTED,
     THREAD_STATUS_HAS_EXCEPTION,
-    PROFILING_MODE_CPU,
-    PROFILING_MODE_GIL,
-    PROFILING_MODE_WALL,
 )
 from .constants import (
     MICROSECONDS_PER_SECOND,
index f5324421b102111a506976ac32782e8497fab25d..ec7e39c0296305678789c23c13c82dc92edeb10c 100644 (file)
@@ -1,6 +1,5 @@
 """Display interface abstractions for the live profiling collector."""
 
-import contextlib
 import curses
 from abc import ABC, abstractmethod
 
index 86d2649f875e6227369d18ad467c3739520e6c86..7535d0c753b0465a432ba5de86825bcd23f3f1ba 100644 (file)
@@ -1,7 +1,6 @@
 """Widget classes for the live profiling collector UI."""
 
 import curses
-import time
 from abc import ABC, abstractmethod
 
 from .constants import (
@@ -13,24 +12,14 @@ from .constants import (
     WIDTH_THRESHOLD_CUMUL_PCT,
     WIDTH_THRESHOLD_CUMTIME,
     MICROSECONDS_PER_SECOND,
-    DISPLAY_UPDATE_INTERVAL_SEC,
     MIN_BAR_WIDTH,
     MAX_SAMPLE_RATE_BAR_WIDTH,
     MAX_EFFICIENCY_BAR_WIDTH,
     MIN_SAMPLE_RATE_FOR_SCALING,
     FOOTER_LINES,
-    FINISHED_BANNER_EXTRA_LINES,
     OPCODE_PANEL_HEIGHT,
 )
-from ..constants import (
-    THREAD_STATUS_HAS_GIL,
-    THREAD_STATUS_ON_CPU,
-    THREAD_STATUS_UNKNOWN,
-    THREAD_STATUS_GIL_REQUESTED,
-    PROFILING_MODE_CPU,
-    PROFILING_MODE_GIL,
-    PROFILING_MODE_WALL,
-)
+from ..constants import PROFILING_MODE_GIL
 from ..opcode_utils import get_opcode_info, format_opcode
 
 
index 50ccc57566d70d37e240d5b8d43cd5552878b0f0..6cb6dd4835208871da537c67e3c88994513b1793 100644 (file)
@@ -8,10 +8,6 @@ import time
 from collections import deque
 lazy from _colorize import ANSIColors
 
-from .pstats_collector import PstatsCollector
-from .stack_collector import CollapsedStackCollector, FlamegraphCollector
-from .heatmap_collector import HeatmapCollector
-from .gecko_collector import GeckoCollector
 from .binary_collector import BinaryCollector
 
 
diff --git a/Tools/.ruff.toml b/Tools/.ruff.toml
new file mode 100644 (file)
index 0000000..fd9cde5
--- /dev/null
@@ -0,0 +1,14 @@
+extend = "../.ruff.toml"  # Inherit the project-wide settings
+
+[per-file-target-version]
+"jit/*.py" = "py312"  # Reused-quote f-strings (PEP 701)
+
+[lint]
+select = [
+    "F401",  # Unused import
+]
+
+[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