https://github.com/python/cpython/commit/328a778db8cc6ecadf0964a8e6a1834078b2d0d3
commit: 328a778db8cc6ecadf0964a8e6a1834078b2d0d3
branch: main
author: Hugo van Kemenade <[email protected]>
committer: hugovk <[email protected]>
date: 2025-05-25T20:09:02Z
summary:
gh-134357: Remove unused imports in tests (#134340)
files:
M Lib/test/.ruff.toml
M Lib/test/support/__init__.py
M Lib/test/support/interpreters/channels.py
M Lib/test/support/interpreters/queues.py
M Lib/test/test_capi/test_config.py
M Lib/test/test_codeccallbacks.py
M Lib/test/test_crossinterp.py
M Lib/test/test_ctypes/_support.py
M Lib/test/test_ctypes/test_byteswap.py
M Lib/test/test_ctypes/test_generated_structs.py
M Lib/test/test_decimal.py
M Lib/test/test_generated_cases.py
M Lib/test/test_genericpath.py
M Lib/test/test_gzip.py
M Lib/test/test_hashlib.py
M Lib/test/test_hmac.py
M Lib/test/test_idle.py
M Lib/test/test_interpreters/test_queues.py
M Lib/test/test_interpreters/utils.py
M Lib/test/test_ntpath.py
M Lib/test/test_peepholer.py
M Lib/test/test_pty.py
M Lib/test/test_pydoc/test_pydoc.py
M Lib/test/test_remote_pdb.py
M Lib/test/test_shutil.py
M Lib/test/test_string/_support.py
M Lib/test/test_sysconfig.py
M Lib/test/test_threading.py
M Lib/test/test_tools/i18n_data/docstrings.py
M Lib/test/test_types.py
M Lib/test/test_typing.py
M Lib/test/test_venv.py
M Lib/test/test_webbrowser.py
M Lib/test/test_zipfile/__main__.py
M Lib/test/test_zstd.py
diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml
index 7aa8a4785d6844..f1a967203ce4ba 100644
--- a/Lib/test/.ruff.toml
+++ b/Lib/test/.ruff.toml
@@ -19,5 +19,12 @@ extend-exclude = [
[lint]
select = [
+ "F401", # Unused import
"F811", # Redefinition of unused variable (useful for finding test
methods with the same name)
]
+
+[lint.per-file-ignores]
+"*/**/__main__.py" = ["F401"] # Unused import
+"test_import/*.py" = ["F401"] # Unused import
+"test_importlib/*.py" = ["F401"] # Unused import
+"typinganndata/partialexecution/*.py" = ["F401"] # Unused import
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index b7cd7940eb15b3..351d832a26d1df 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1101,7 +1101,6 @@ def __init__(self):
self.started = False
def start(self):
- import warnings
try:
f = open(self.procfile, 'r')
except OSError as e:
@@ -2728,7 +2727,7 @@ def iter_builtin_types():
# Fall back to making a best-effort guess.
if hasattr(object, '__flags__'):
# Look for any type object with the Py_TPFLAGS_STATIC_BUILTIN flag set.
- import datetime
+ import datetime # noqa: F401
seen = set()
for cls, subs in walk_class_hierarchy(object):
if cls in seen:
diff --git a/Lib/test/support/interpreters/channels.py
b/Lib/test/support/interpreters/channels.py
index 7a2bd7d63f808f..b25a17b1aabb93 100644
--- a/Lib/test/support/interpreters/channels.py
+++ b/Lib/test/support/interpreters/channels.py
@@ -6,8 +6,8 @@
# aliases:
from _interpchannels import (
- ChannelError, ChannelNotFoundError, ChannelClosedError,
- ChannelEmptyError, ChannelNotEmptyError,
+ ChannelError, ChannelNotFoundError, ChannelClosedError, # noqa: F401
+ ChannelEmptyError, ChannelNotEmptyError, # noqa: F401
)
from ._crossinterp import (
UNBOUND_ERROR, UNBOUND_REMOVE,
diff --git a/Lib/test/support/interpreters/queues.py
b/Lib/test/support/interpreters/queues.py
index d6a3197d9e0e26..99987f2f6926b0 100644
--- a/Lib/test/support/interpreters/queues.py
+++ b/Lib/test/support/interpreters/queues.py
@@ -1,6 +1,5 @@
"""Cross-interpreter Queues High Level Module."""
-import pickle
import queue
import time
import weakref
diff --git a/Lib/test/test_capi/test_config.py
b/Lib/test/test_capi/test_config.py
index a2d70dd3af482d..04a27de8d84994 100644
--- a/Lib/test/test_capi/test_config.py
+++ b/Lib/test/test_capi/test_config.py
@@ -3,7 +3,6 @@
"""
import os
import sys
-import sysconfig
import types
import unittest
from test import support
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
index a767f67a02cf56..65d54d1004d647 100644
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -2,7 +2,6 @@
import codecs
import html.entities
import itertools
-import re
import sys
import unicodedata
import unittest
diff --git a/Lib/test/test_crossinterp.py b/Lib/test/test_crossinterp.py
index c54635eaeab3f9..2fa0077a09bbbb 100644
--- a/Lib/test/test_crossinterp.py
+++ b/Lib/test/test_crossinterp.py
@@ -1,6 +1,4 @@
import contextlib
-import importlib
-import importlib.util
import itertools
import sys
import types
diff --git a/Lib/test/test_ctypes/_support.py b/Lib/test/test_ctypes/_support.py
index 946d654a19aff8..700657a4e41f74 100644
--- a/Lib/test/test_ctypes/_support.py
+++ b/Lib/test/test_ctypes/_support.py
@@ -3,7 +3,6 @@
import ctypes
from _ctypes import Structure, Union, _Pointer, Array, _SimpleCData, CFuncPtr
import sys
-from test import support
_CData = Structure.__base__
diff --git a/Lib/test/test_ctypes/test_byteswap.py
b/Lib/test/test_ctypes/test_byteswap.py
index ea5951603f9324..f14e1aa32e17ab 100644
--- a/Lib/test/test_ctypes/test_byteswap.py
+++ b/Lib/test/test_ctypes/test_byteswap.py
@@ -1,5 +1,4 @@
import binascii
-import ctypes
import math
import struct
import sys
diff --git a/Lib/test/test_ctypes/test_generated_structs.py
b/Lib/test/test_ctypes/test_generated_structs.py
index aa448fad5bbae6..1cb46a82701553 100644
--- a/Lib/test/test_ctypes/test_generated_structs.py
+++ b/Lib/test/test_ctypes/test_generated_structs.py
@@ -10,7 +10,7 @@
"""
import unittest
-from test.support import import_helper, verbose
+from test.support import import_helper
import re
from dataclasses import dataclass
from functools import cached_property
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 9e298401dc3dcc..c0a1e378583ba8 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -28,7 +28,6 @@
import math
import os, sys
import operator
-import warnings
import pickle, copy
import unittest
import numbers
diff --git a/Lib/test/test_generated_cases.py b/Lib/test/test_generated_cases.py
index a71ddc01d1c045..37046d8e1c02b7 100644
--- a/Lib/test/test_generated_cases.py
+++ b/Lib/test/test_generated_cases.py
@@ -1,11 +1,9 @@
import contextlib
import os
-import re
import sys
import tempfile
import unittest
-from io import StringIO
from test import support
from test import test_tools
@@ -31,12 +29,11 @@ def skip_if_different_mount_drives():
test_tools.skip_if_missing("cases_generator")
with test_tools.imports_under_tool("cases_generator"):
- from analyzer import analyze_forest, StackItem
+ from analyzer import StackItem
from cwriter import CWriter
import parser
from stack import Local, Stack
import tier1_generator
- import opcode_metadata_generator
import optimizer_generator
diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py
index df07af01fc7540..16c3268fefb034 100644
--- a/Lib/test/test_genericpath.py
+++ b/Lib/test/test_genericpath.py
@@ -8,7 +8,7 @@
import unittest
import warnings
from test.support import (
- is_apple, is_emscripten, os_helper, warnings_helper
+ is_apple, os_helper, warnings_helper
)
from test.support.script_helper import assert_python_ok
from test.support.os_helper import FakePath
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index ccbacc7c19b6e6..a12ff5662a73db 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -9,7 +9,6 @@
import struct
import sys
import unittest
-import warnings
from subprocess import PIPE, Popen
from test.support import catch_unraisable_exception
from test.support import import_helper
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index de4c8a1670f591..161c7652d7ab11 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -17,7 +17,6 @@
import tempfile
import threading
import unittest
-import warnings
from test import support
from test.support import _4G, bigmemtest
from test.support import hashlib_helper
diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py
index e898644dd8a552..ff6e1bce0ef801 100644
--- a/Lib/test/test_hmac.py
+++ b/Lib/test/test_hmac.py
@@ -21,7 +21,6 @@
import hmac
import hashlib
import random
-import test.support
import test.support.hashlib_helper as hashlib_helper
import types
import unittest
diff --git a/Lib/test/test_idle.py b/Lib/test/test_idle.py
index 3d8b7ecc0ecb6d..ebf572ac5caac1 100644
--- a/Lib/test/test_idle.py
+++ b/Lib/test/test_idle.py
@@ -16,7 +16,7 @@
# Unittest.main and test.libregrtest.runtest.runtest_inner
# call load_tests, when present here, to discover tests to run.
-from idlelib.idle_test import load_tests
+from idlelib.idle_test import load_tests # noqa: F401
if __name__ == '__main__':
tk.NoDefaultRoot()
diff --git a/Lib/test/test_interpreters/test_queues.py
b/Lib/test/test_interpreters/test_queues.py
index 64a2db1230d023..757373904d7a43 100644
--- a/Lib/test/test_interpreters/test_queues.py
+++ b/Lib/test/test_interpreters/test_queues.py
@@ -9,7 +9,6 @@
_queues = import_helper.import_module('_interpqueues')
from test.support import interpreters
from test.support.interpreters import queues, _crossinterp
-import test._crossinterp_definitions as defs
from .utils import _run_output, TestBase as _TestBase
diff --git a/Lib/test/test_interpreters/utils.py
b/Lib/test/test_interpreters/utils.py
index fc4ad662e03b66..c25e0fb7475e7e 100644
--- a/Lib/test/test_interpreters/utils.py
+++ b/Lib/test/test_interpreters/utils.py
@@ -12,7 +12,6 @@
import threading
import types
import unittest
-import warnings
from test import support
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index f83ef225a6e48e..c3b0bdaebc2329 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -6,8 +6,7 @@
import sys
import unittest
import warnings
-from test.support import cpython_only, os_helper
-from test.support import TestFailed, is_emscripten
+from test.support import TestFailed, cpython_only, os_helper
from test.support.os_helper import FakePath
from test import test_genericpath
from tempfile import TemporaryFile
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py
index 0a9ba578673b39..f33de3d420ca34 100644
--- a/Lib/test/test_peepholer.py
+++ b/Lib/test/test_peepholer.py
@@ -12,7 +12,7 @@
from test import support
from test.support.bytecode_helper import (
- BytecodeTestCase, CfgOptimizationTestCase, CompilationStepTestCase)
+ BytecodeTestCase, CfgOptimizationTestCase)
def compile_pattern_with_fast_locals(pattern):
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py
index c1728f5019d042..4836f38c388c05 100644
--- a/Lib/test/test_pty.py
+++ b/Lib/test/test_pty.py
@@ -20,7 +20,6 @@
import signal
import socket
import io # readline
-import warnings
TEST_STRING_1 = b"I wish to buy a fish license.\n"
TEST_STRING_2 = b"For my pet fish, Eric.\n"
diff --git a/Lib/test/test_pydoc/test_pydoc.py
b/Lib/test/test_pydoc/test_pydoc.py
index 281b24eaa36b80..d1d6f4987def0c 100644
--- a/Lib/test/test_pydoc/test_pydoc.py
+++ b/Lib/test/test_pydoc/test_pydoc.py
@@ -553,7 +553,7 @@ class object
# of the known subclasses of object. (doc.docclass() used to
# fail if HeapType was imported before running this test, like
# when running tests sequentially.)
- from _testcapi import HeapType
+ from _testcapi import HeapType # noqa: F401
except ImportError:
pass
text = doc.docclass(object)
diff --git a/Lib/test/test_remote_pdb.py b/Lib/test/test_remote_pdb.py
index aef8a6b0129092..a1c50af15f3dd2 100644
--- a/Lib/test/test_remote_pdb.py
+++ b/Lib/test/test_remote_pdb.py
@@ -1,5 +1,4 @@
import io
-import time
import itertools
import json
import os
@@ -8,16 +7,13 @@
import socket
import subprocess
import sys
-import tempfile
import textwrap
-import threading
import unittest
import unittest.mock
from contextlib import closing, contextmanager, redirect_stdout,
redirect_stderr, ExitStack
-from pathlib import Path
from test.support import is_wasi, cpython_only, force_color,
requires_subprocess, SHORT_TIMEOUT
-from test.support.os_helper import temp_dir, TESTFN, unlink
-from typing import Dict, List, Optional, Tuple, Union, Any
+from test.support.os_helper import TESTFN, unlink
+from typing import List
import pdb
from pdb import _PdbServer, _PdbClient
@@ -1434,7 +1430,6 @@ def test_multi_line_commands(self):
def _supports_remote_attaching():
- from contextlib import suppress
PROCESS_VM_READV_SUPPORTED = False
try:
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 62c80aab4b3305..ebb6cf88336249 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -3492,7 +3492,7 @@ def test_module_all_attribute(self):
target_api.append('disk_usage')
self.assertEqual(set(shutil.__all__), set(target_api))
with self.assertWarns(DeprecationWarning):
- from shutil import ExecError
+ from shutil import ExecError # noqa: F401
if __name__ == '__main__':
diff --git a/Lib/test/test_string/_support.py b/Lib/test/test_string/_support.py
index eaa3354a559246..abdddaf187b4fe 100644
--- a/Lib/test/test_string/_support.py
+++ b/Lib/test/test_string/_support.py
@@ -1,4 +1,3 @@
-import unittest
from string.templatelib import Interpolation
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index d30f69ded6643a..2c0df9376abfc6 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -32,7 +32,6 @@
from sysconfig.__main__ import _main, _parse_makefile, _get_pybuilddir,
_get_json_data_name
import _imp
import _osx_support
-import _sysconfig
HAS_USER_BASE = sysconfig._HAS_USER_BASE
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 0e51e7fc8c5a76..59b3a749d2fffa 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -1253,7 +1253,7 @@ def test_start_new_thread_failed(self):
# its state should be removed from interpreter' thread states list
# to avoid its double cleanup
try:
- from resource import setrlimit, RLIMIT_NPROC
+ from resource import setrlimit, RLIMIT_NPROC # noqa: F401
except ImportError as err:
self.skipTest(err) # RLIMIT_NPROC is specific to Linux and BSD
code = """if 1:
diff --git a/Lib/test/test_tools/i18n_data/docstrings.py
b/Lib/test/test_tools/i18n_data/docstrings.py
index 151a55a4b56ba6..14559a632da158 100644
--- a/Lib/test/test_tools/i18n_data/docstrings.py
+++ b/Lib/test/test_tools/i18n_data/docstrings.py
@@ -1,7 +1,7 @@
"""Module docstring"""
# Test docstring extraction
-from gettext import gettext as _
+from gettext import gettext as _ # noqa: F401
# Empty docstring
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 3097c7ddf05901..9011e0e1962820 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -2516,7 +2516,7 @@ def setUpClass(cls):
from test.support import interpreters
except ModuleNotFoundError:
raise unittest.SkipTest('subinterpreters required')
- import test.support.interpreters.channels
+ import test.support.interpreters.channels # noqa: F401
@cpython_only
@no_rerun('channels (and queues) might have a refleak; see gh-122199')
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index e2b6f459aa24fc..ef02e8202fc829 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -46,11 +46,10 @@
import textwrap
import typing
import weakref
-import warnings
import types
from test.support import (
- captured_stderr, cpython_only, infinite_recursion, requires_docstrings,
import_helper, run_code,
+ captured_stderr, cpython_only, requires_docstrings, import_helper,
run_code,
EqualToForwardRef,
)
from test.typinganndata import (
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index 12c30e178aeb51..d62f3fba2d1a94 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -1008,7 +1008,7 @@ def do_test_with_pip(self, system_site_packages):
err, flags=re.MULTILINE)
# Ignore warning about missing optional module:
try:
- import ssl
+ import ssl # noqa: F401
except ImportError:
err = re.sub(
"^WARNING: Disabling truststore since ssl support is missing$",
diff --git a/Lib/test/test_webbrowser.py b/Lib/test/test_webbrowser.py
index 4c3ea1cd8df13e..6b577ae100e419 100644
--- a/Lib/test/test_webbrowser.py
+++ b/Lib/test/test_webbrowser.py
@@ -6,7 +6,6 @@
import sys
import unittest
import webbrowser
-from functools import partial
from test import support
from test.support import import_helper
from test.support import is_apple_mobile
diff --git a/Lib/test/test_zipfile/__main__.py
b/Lib/test/test_zipfile/__main__.py
index e25ac946edffe4..90da74ade38c69 100644
--- a/Lib/test/test_zipfile/__main__.py
+++ b/Lib/test/test_zipfile/__main__.py
@@ -1,6 +1,6 @@
import unittest
-from . import load_tests # noqa: F401
+from . import load_tests
if __name__ == "__main__":
diff --git a/Lib/test/test_zstd.py b/Lib/test/test_zstd.py
index 34c7c721b1ad32..bc809603cbc629 100644
--- a/Lib/test/test_zstd.py
+++ b/Lib/test/test_zstd.py
@@ -12,7 +12,6 @@
from test.support.import_helper import import_module
from test.support import threading_helper
from test.support import _1M
-from test.support import Py_GIL_DISABLED
_zstd = import_module("_zstd")
zstd = import_module("compression.zstd")
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]