8000 gh-134357: Remove unused imports in tests (#134340) · faster-cpython/cpython@328a778 · GitHub
[go: up one dir, main page]

Skip to content

Commit 328a778

Browse files
authored
pythongh-134357: Remove unused imports in tests (python#134340)
1 parent 24a4715 commit 328a778

35 files changed

+26
-48
lines changed

Lib/test/.ruff.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,12 @@ extend-exclude = [
1919

2020
[lint]
2121
select = [
22+
"F401", # Unused import
2223
"F811", # Redefinition of unused variable (useful for finding test methods with the same name)
2324
]
25+
26+
[lint.per-file-ignores]
27+
"*/**/__main__.py" = ["F401"] # Unused import
28+
"test_import/*.py" = ["F401"] # Unused import
29+
"test_importlib/*.py" = ["F401"] # Unused import
30+
"typinganndata/partialexecution/*.py" = ["F401"] # Unused import

Lib/test/support/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,6 @@ def __init__(self):
11011101
self.started = False
11021102

11031103
def start(self):
1104-
import warnings
11051104
try:
11061105
f = open(self.procfile, 'r')
11071106
except OSError as e:
@@ -2728,7 +2727,7 @@ def iter_builtin_types():
27282727
# Fall back to making a best-effort guess.
27292728
if hasattr(object, '__flags__'):
27302729
# Look for any type object with the Py_TPFLAGS_STATIC_BUILTIN flag set.
2731-
import datetime
2730+
import datetime # noqa: F401
27322731
seen = set()
27332732
for cls, subs in walk_class_hierarchy(object):
27342733
if cls in seen:

Lib/test/support/interpreters/channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# aliases:
88
from _interpchannels import (
9-
ChannelError, ChannelNotFoundError, ChannelClosedError,
10-
ChannelEmptyError, ChannelNotEmptyError,
9+
ChannelError, ChannelNotFoundError, ChannelClosedError, # noqa: F401
10+
ChannelEmptyError, ChannelNotEmptyError, # noqa: F401
1111
)
1212
from ._crossinterp import (
1313
UNBOUND_ERROR, UNBOUND_REMOVE,

Lib/test/support/interpreters/queues.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Cross-interpreter Queues High Level Module."""
22

3-
import pickle
43
import queue
54
import time
65
import weakref

Lib/test/test_capi/test_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
import os
55
import sys
6-
import sysconfig
76
import types
87
import unittest
98
from test import support

Lib/test/test_codeccallbacks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import codecs
33
import html.entities
44
import itertools
5-
import re
65
import sys
76
import unicodedata
87
import unittest

Lib/test/test_crossinterp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import contextlib
2-
import importlib
3-
import importlib.util
42
import itertools
53
import sys
64
import types

Lib/test/test_ctypes/_support.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import ctypes
44
from _ctypes import Structure, Union, _Pointer, Array, _SimpleCData, CFuncPtr
55
import sys
6-
from test import support
76

87

98
_CData = Structure.__base__

Lib/test/test_ctypes/test_byteswap.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import binascii
2-
import ctypes
32
import math
43
import struct
54
import sys

Lib/test/test_ctypes/test_generated_structs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"""
1111

1212
import unittest
13-
from test.support import import_helper, verbose
13+
from test.support import import_helper
1414
import re
1515
from dataclasses import dataclass
1616
from functools import cached_property

Lib/test/test_decimal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import math
2929
import os, sys
3030
import operator
31-
import warnings
3231
import pickle, copy
3332
import unittest
3433
import numbers

Lib/test/test_generated_cases.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import contextlib
22
import os
3-
import re
43
import sys
54
import tempfile
65
import unittest
76

8-
from io import StringIO
97
from test import support
108
from test import test_tools
119

@@ -31,12 +29,11 @@ def skip_if_different_mount_drives():
3129

3230
test_tools.skip_if_missing("cases_generator")
3331
with test_tools.imports_under_tool("cases_generator"):
34-
from analyzer import analyze_forest, StackItem
32+
from analyzer import StackItem
3533
from cwriter import CWriter
3634
import parser
3735
from stack import Local, Stack
3836
import tier1_generator
39-
import opcode_metadata_generator
4037
import optimizer_generator
4138

4239

Lib/test/test_genericpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import unittest
99
import warnings
1010
from test.support import (
11-
is_apple, is_emscripten, os_helper, warnings_helper
11+
is_apple, os_helper, warnings_helper
1212
)
1313
from test.support.script_helper import assert_python_ok
1414
from test.support.os_helper import FakePath

Lib/test/test_gzip.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import struct
1010
import sys
1111
import unittest
12-
import warnings
1312
from subprocess import PIPE, Popen
1413
from test.support import catch_unraisable_exception
1514
from test.support import import_helper

Lib/test/test_hashlib.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import tempfile
1818
import threading
1919
import unittest
20-
import warnings
2120
from test import support
2221
from test.support import _4G, bigmemtest
2322
from test.support import hashlib_helper

Lib/test/test_hmac.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import hmac
2222
import hashlib
2323
import random
24-
import test.support
2524
import test.support.hashlib_helper as hashlib_helper
2625
import types
2726
import unittest

Lib/test/test_idle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Unittest.main and test.libregrtest.runtest.runtest_inner
1818
# call load_tests, when present here, to discover tests to run.
19-
from idlelib.idle_test import load_tests
19+
from idlelib.idle_test import load_tests # noqa: F401
2020

2121
if __name__ == '__main__':
2222
tk.NoDefaultRoot()

Lib/test/test_interpreters/test_queues.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
_queues = import_helper.import_module('_interpqueues')
1010
from test.support import interpreters
1111
from test.support.interpreters import queues, _crossinterp
12-
import test._crossinterp_definitions as defs
1312
from .utils import _run_output, TestBase as _TestBase
1413

1514

Lib/test/test_interpreters/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import threading
1313
import types
1414
import unittest
15-
import warnings
1615

1716
from test import support
1817

Lib/test/test_ntpath.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import sys
77
import unittest
88
import warnings
9-
from test.support import cpython_only, os_helper
10-
from test.support import TestFailed, is_emscripten
9+
from test.support import TestFailed, cpython_only, os_helper
1110
from test.support.os_helper import FakePath
1211
from test import test_genericpath
1312
from tempfile import TemporaryFile

Lib/test/test_peepholer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from test import support
1414
from test.support.bytecode_helper import (
15-
BytecodeTestCase, CfgOptimizationTestCase, CompilationStepTestCase)
15+
BytecodeTestCase, CfgOptimizationTestCase)
1616

1717

1818
def compile_pattern_with_fast_locals(pattern):

Lib/test/test_pty.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import signal
2121
import socket
2222
import io # readline
23-
import warnings
2423

2524
TEST_STRING_1 = b"I wish to buy a fish license.\n"
2625
TEST_STRING_2 = b"For my pet fish, Eric.\n"

Lib/test/test_pydoc/test_pydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class object
553553
# of the known subclasses of object. (doc.docclass() used to
554554
# fail if HeapType was imported before running this test, like
555555
# when running tests sequentially.)
556-
from _testcapi import HeapType
556+
from _testcapi import HeapType # noqa: F401
557557
except ImportError:
558558
pass
559559
text = doc.docclass(object)

Lib/test/test_remote_pdb.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io
2-
import time
32
import itertools
43
import json
54
import os
@@ -8,16 +7,13 @@
87
import socket
98
import subprocess
109
import sys
11-
import tempfile
1210
import textwrap
13-
import threading
1411
import unittest
1512
import unittest.mock
1613
from contextlib import closing, contextmanager, redirect_stdout, redirect_stderr, ExitStack
17-
from pathlib import Path
1814
from test.support import is_wasi, cpython_only, force_color, requires_subprocess, SHORT_TIMEOUT
19-
from test.support.os_helper import temp_dir, TESTFN, unlink
20-
from typing import Dict, List, Optional, Tuple, Union, Any
15+
from test.support.os_helper import TESTFN, unlink
16+
from typing import List
2117

2218
import pdb
2319
from pdb import _PdbServer, _PdbClient
@@ -1434,7 +1430,6 @@ def test_multi_line_commands(self):
14341430

14351431

14361432
def _supports_remote_attaching():
1437-
from contextlib import suppress
14381433
PROCESS_VM_READV_SUPPORTED = False
14391434

14401435
try:

Lib/test/test_shutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,7 @@ def test_module_all_attribute(self):
34923492
target_api.append('disk_usage')
34933493
self.assertEqual(set(shutil.__all__), set(target_api))
34943494
with self.assertWarns(DeprecationWarning):
3495-
from shutil import ExecError
3495+
from shutil import ExecError # noqa: F401
34963496

34973497

34983498
if __name__ == '__main__':

Lib/test/test_string/_support.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import unittest
21
from string.templatelib import Interpolation
32

43

Lib/test/test_sysconfig.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from sysconfig.__main__ import _main, _parse_makefile, _get_pybuilddir, _get_json_data_name
3333
import _imp
3434
import _osx_support
35-
import _sysconfig
3635

3736

3837
HAS_USER_BASE = sysconfig._HAS_USER_BASE

Lib/test/test_threading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ def test_start_new_thread_failed(self):
12531253
# its state should be removed from interpreter' thread states list
12541254
# to avoid its double cleanup
12551255
try:
1256-
from resource import setrlimit, RLIMIT_NPROC
1256+
from resource import setrlimit, RLIMIT_NPROC # noqa: F401
12571257
except ImportError as err:
12581258
self.skipTest(err) # RLIMIT_NPROC is specific to Linux and BSD
12591259
code = """if 1:

Lib/test/test_tools/i18n_data/docstrings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Module docstring"""
22

33
# Test docstring extraction
4-
from gettext import gettext as _
4+
from gettext import gettext as _ # noqa: F401
55

66

77
# Empty docstring

Lib/test/test_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ def setUpClass(cls):
25162516
from test.support import interpreters
25172517
except ModuleNotFoundError:
25182518
raise unittest.SkipTest('subinterpreters required')
2519-
import test.support.interpreters.channels
2519+
import test.support.interpreters.channels # noqa: F401
25202520

25212521
@cpython_only
25222522
@no_rerun('channels (and queues) might have a refleak; see gh-122199')

Lib/test/test_typing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@
4646
import textwrap
4747
import typing
4848
import weakref
49-
import warnings
5049
import types
5150

5251
from test.support import (
53-
captured_stderr, cpython_only, infinite_recursion, requires_docstrings, import_helper, run_code,
52+
captured_stderr, cpython_only, requires_docstrings, import_helper, run_code,
5453
EqualToForwardRef,
5554
)
5655
from test.typinganndata import (

Lib/test/test_venv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ def do_test_with_pip(self, system_site_packages):
10081008
err, flags=re.MULTILINE)
10091009
# Ignore warning about missing optional module:
10101010
try:
1011-
import ssl
1011+
import ssl # noqa: F401
10121012
except ImportError:
10131013
err = re.sub(
10141014
"^WARNING: Disabling truststore since ssl support is missing$",

Lib/test/test_webbrowser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77
import unittest
88
import webbrowser
9-
from functools import partial
109
from test import support
1110
from test.support import import_helper
1211
from test.support import is_apple_mobile

Lib/test/test_zipfile/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from . import load_tests # noqa: F401
3+
from . import load_tests
44

55

66
if __name__ == "__main__":

Lib/test/test_zstd.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from test.support.import_helper import import_module
1313
from test.support import threading_helper
1414
from test.support import _1M
15-
from test.support import Py_GIL_DISABLED
1615

1716
_zstd = import_module("_zstd")
1817
zstd = import_module("compression.zstd")

0 commit comments

Comments
 (0)
0