mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-134357: Remove unused imports in tests (#134340)
This commit is contained in:
parent
24a47155d2
commit
328a778db8
35 changed files with 26 additions and 48 deletions
|
@ -19,5 +19,12 @@ extend-exclude = [
|
||||||
|
|
||||||
[lint]
|
[lint]
|
||||||
select = [
|
select = [
|
||||||
|
"F401", # Unused import
|
||||||
"F811", # Redefinition of unused variable (useful for finding test methods with the same name)
|
"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
|
||||||
|
|
|
@ -1101,7 +1101,6 @@ class _MemoryWatchdog:
|
||||||
self.started = False
|
self.started = False
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
import warnings
|
|
||||||
try:
|
try:
|
||||||
f = open(self.procfile, 'r')
|
f = open(self.procfile, 'r')
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
@ -2728,7 +2727,7 @@ def iter_builtin_types():
|
||||||
# Fall back to making a best-effort guess.
|
# Fall back to making a best-effort guess.
|
||||||
if hasattr(object, '__flags__'):
|
if hasattr(object, '__flags__'):
|
||||||
# Look for any type object with the Py_TPFLAGS_STATIC_BUILTIN flag set.
|
# Look for any type object with the Py_TPFLAGS_STATIC_BUILTIN flag set.
|
||||||
import datetime
|
import datetime # noqa: F401
|
||||||
seen = set()
|
seen = set()
|
||||||
for cls, subs in walk_class_hierarchy(object):
|
for cls, subs in walk_class_hierarchy(object):
|
||||||
if cls in seen:
|
if cls in seen:
|
||||||
|
|
|
@ -6,8 +6,8 @@ from . import _crossinterp
|
||||||
|
|
||||||
# aliases:
|
# aliases:
|
||||||
from _interpchannels import (
|
from _interpchannels import (
|
||||||
ChannelError, ChannelNotFoundError, ChannelClosedError,
|
ChannelError, ChannelNotFoundError, ChannelClosedError, # noqa: F401
|
||||||
ChannelEmptyError, ChannelNotEmptyError,
|
ChannelEmptyError, ChannelNotEmptyError, # noqa: F401
|
||||||
)
|
)
|
||||||
from ._crossinterp import (
|
from ._crossinterp import (
|
||||||
UNBOUND_ERROR, UNBOUND_REMOVE,
|
UNBOUND_ERROR, UNBOUND_REMOVE,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""Cross-interpreter Queues High Level Module."""
|
"""Cross-interpreter Queues High Level Module."""
|
||||||
|
|
||||||
import pickle
|
|
||||||
import queue
|
import queue
|
||||||
import time
|
import time
|
||||||
import weakref
|
import weakref
|
||||||
|
|
|
@ -3,7 +3,6 @@ Tests PyConfig_Get() and PyConfig_Set() C API (PEP 741).
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import sysconfig
|
|
||||||
import types
|
import types
|
||||||
import unittest
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
|
|
@ -2,7 +2,6 @@ from _codecs import _unregister_error as _codecs_unregister_error
|
||||||
import codecs
|
import codecs
|
||||||
import html.entities
|
import html.entities
|
||||||
import itertools
|
import itertools
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import unittest
|
import unittest
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
import importlib
|
|
||||||
import importlib.util
|
|
||||||
import itertools
|
import itertools
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
import ctypes
|
import ctypes
|
||||||
from _ctypes import Structure, Union, _Pointer, Array, _SimpleCData, CFuncPtr
|
from _ctypes import Structure, Union, _Pointer, Array, _SimpleCData, CFuncPtr
|
||||||
import sys
|
import sys
|
||||||
from test import support
|
|
||||||
|
|
||||||
|
|
||||||
_CData = Structure.__base__
|
_CData = Structure.__base__
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import binascii
|
import binascii
|
||||||
import ctypes
|
|
||||||
import math
|
import math
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -10,7 +10,7 @@ Run this module to regenerate the files:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import import_helper, verbose
|
from test.support import import_helper
|
||||||
import re
|
import re
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
|
|
|
@ -28,7 +28,6 @@ import logging
|
||||||
import math
|
import math
|
||||||
import os, sys
|
import os, sys
|
||||||
import operator
|
import operator
|
||||||
import warnings
|
|
||||||
import pickle, copy
|
import pickle, copy
|
||||||
import unittest
|
import unittest
|
||||||
import numbers
|
import numbers
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from io import StringIO
|
|
||||||
from test import support
|
from test import support
|
||||||
from test import test_tools
|
from test import test_tools
|
||||||
|
|
||||||
|
@ -31,12 +29,11 @@ skip_if_different_mount_drives()
|
||||||
|
|
||||||
test_tools.skip_if_missing("cases_generator")
|
test_tools.skip_if_missing("cases_generator")
|
||||||
with test_tools.imports_under_tool("cases_generator"):
|
with test_tools.imports_under_tool("cases_generator"):
|
||||||
from analyzer import analyze_forest, StackItem
|
from analyzer import StackItem
|
||||||
from cwriter import CWriter
|
from cwriter import CWriter
|
||||||
import parser
|
import parser
|
||||||
from stack import Local, Stack
|
from stack import Local, Stack
|
||||||
import tier1_generator
|
import tier1_generator
|
||||||
import opcode_metadata_generator
|
|
||||||
import optimizer_generator
|
import optimizer_generator
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import sys
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
import warnings
|
||||||
from test.support import (
|
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.script_helper import assert_python_ok
|
||||||
from test.support.os_helper import FakePath
|
from test.support.os_helper import FakePath
|
||||||
|
|
|
@ -9,7 +9,6 @@ import os
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
from subprocess import PIPE, Popen
|
from subprocess import PIPE, Popen
|
||||||
from test.support import catch_unraisable_exception
|
from test.support import catch_unraisable_exception
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
|
|
|
@ -17,7 +17,6 @@ import sysconfig
|
||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import _4G, bigmemtest
|
from test.support import _4G, bigmemtest
|
||||||
from test.support import hashlib_helper
|
from test.support import hashlib_helper
|
||||||
|
|
|
@ -21,7 +21,6 @@ import functools
|
||||||
import hmac
|
import hmac
|
||||||
import hashlib
|
import hashlib
|
||||||
import random
|
import random
|
||||||
import test.support
|
|
||||||
import test.support.hashlib_helper as hashlib_helper
|
import test.support.hashlib_helper as hashlib_helper
|
||||||
import types
|
import types
|
||||||
import unittest
|
import unittest
|
||||||
|
|
|
@ -16,7 +16,7 @@ idlelib.testing = True
|
||||||
|
|
||||||
# Unittest.main and test.libregrtest.runtest.runtest_inner
|
# Unittest.main and test.libregrtest.runtest.runtest_inner
|
||||||
# call load_tests, when present here, to discover tests to run.
|
# 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__':
|
if __name__ == '__main__':
|
||||||
tk.NoDefaultRoot()
|
tk.NoDefaultRoot()
|
||||||
|
|
|
@ -9,7 +9,6 @@ from test.support import import_helper, Py_DEBUG
|
||||||
_queues = import_helper.import_module('_interpqueues')
|
_queues = import_helper.import_module('_interpqueues')
|
||||||
from test.support import interpreters
|
from test.support import interpreters
|
||||||
from test.support.interpreters import queues, _crossinterp
|
from test.support.interpreters import queues, _crossinterp
|
||||||
import test._crossinterp_definitions as defs
|
|
||||||
from .utils import _run_output, TestBase as _TestBase
|
from .utils import _run_output, TestBase as _TestBase
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ from textwrap import dedent
|
||||||
import threading
|
import threading
|
||||||
import types
|
import types
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
import warnings
|
||||||
from test.support import cpython_only, os_helper
|
from test.support import TestFailed, cpython_only, os_helper
|
||||||
from test.support import TestFailed, is_emscripten
|
|
||||||
from test.support.os_helper import FakePath
|
from test.support.os_helper import FakePath
|
||||||
from test import test_genericpath
|
from test import test_genericpath
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
|
|
|
@ -12,7 +12,7 @@ except ImportError:
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
from test.support.bytecode_helper import (
|
from test.support.bytecode_helper import (
|
||||||
BytecodeTestCase, CfgOptimizationTestCase, CompilationStepTestCase)
|
BytecodeTestCase, CfgOptimizationTestCase)
|
||||||
|
|
||||||
|
|
||||||
def compile_pattern_with_fast_locals(pattern):
|
def compile_pattern_with_fast_locals(pattern):
|
||||||
|
|
|
@ -20,7 +20,6 @@ import select
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import io # readline
|
import io # readline
|
||||||
import warnings
|
|
||||||
|
|
||||||
TEST_STRING_1 = b"I wish to buy a fish license.\n"
|
TEST_STRING_1 = b"I wish to buy a fish license.\n"
|
||||||
TEST_STRING_2 = b"For my pet fish, Eric.\n"
|
TEST_STRING_2 = b"For my pet fish, Eric.\n"
|
||||||
|
|
|
@ -553,7 +553,7 @@ class PydocDocTest(unittest.TestCase):
|
||||||
# of the known subclasses of object. (doc.docclass() used to
|
# of the known subclasses of object. (doc.docclass() used to
|
||||||
# fail if HeapType was imported before running this test, like
|
# fail if HeapType was imported before running this test, like
|
||||||
# when running tests sequentially.)
|
# when running tests sequentially.)
|
||||||
from _testcapi import HeapType
|
from _testcapi import HeapType # noqa: F401
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
text = doc.docclass(object)
|
text = doc.docclass(object)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import io
|
import io
|
||||||
import time
|
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
@ -8,16 +7,13 @@ import signal
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
import textwrap
|
import textwrap
|
||||||
import threading
|
|
||||||
import unittest
|
import unittest
|
||||||
import unittest.mock
|
import unittest.mock
|
||||||
from contextlib import closing, contextmanager, redirect_stdout, redirect_stderr, ExitStack
|
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 import is_wasi, cpython_only, force_color, requires_subprocess, SHORT_TIMEOUT
|
||||||
from test.support.os_helper import temp_dir, TESTFN, unlink
|
from test.support.os_helper import TESTFN, unlink
|
||||||
from typing import Dict, List, Optional, Tuple, Union, Any
|
from typing import List
|
||||||
|
|
||||||
import pdb
|
import pdb
|
||||||
from pdb import _PdbServer, _PdbClient
|
from pdb import _PdbServer, _PdbClient
|
||||||
|
@ -1434,7 +1430,6 @@ class PdbConnectTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
def _supports_remote_attaching():
|
def _supports_remote_attaching():
|
||||||
from contextlib import suppress
|
|
||||||
PROCESS_VM_READV_SUPPORTED = False
|
PROCESS_VM_READV_SUPPORTED = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -3492,7 +3492,7 @@ class PublicAPITests(unittest.TestCase):
|
||||||
target_api.append('disk_usage')
|
target_api.append('disk_usage')
|
||||||
self.assertEqual(set(shutil.__all__), set(target_api))
|
self.assertEqual(set(shutil.__all__), set(target_api))
|
||||||
with self.assertWarns(DeprecationWarning):
|
with self.assertWarns(DeprecationWarning):
|
||||||
from shutil import ExecError
|
from shutil import ExecError # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import unittest
|
|
||||||
from string.templatelib import Interpolation
|
from string.templatelib import Interpolation
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ from sysconfig import (get_paths, get_platform, get_config_vars,
|
||||||
from sysconfig.__main__ import _main, _parse_makefile, _get_pybuilddir, _get_json_data_name
|
from sysconfig.__main__ import _main, _parse_makefile, _get_pybuilddir, _get_json_data_name
|
||||||
import _imp
|
import _imp
|
||||||
import _osx_support
|
import _osx_support
|
||||||
import _sysconfig
|
|
||||||
|
|
||||||
|
|
||||||
HAS_USER_BASE = sysconfig._HAS_USER_BASE
|
HAS_USER_BASE = sysconfig._HAS_USER_BASE
|
||||||
|
|
|
@ -1253,7 +1253,7 @@ class ThreadTests(BaseTestCase):
|
||||||
# its state should be removed from interpreter' thread states list
|
# its state should be removed from interpreter' thread states list
|
||||||
# to avoid its double cleanup
|
# to avoid its double cleanup
|
||||||
try:
|
try:
|
||||||
from resource import setrlimit, RLIMIT_NPROC
|
from resource import setrlimit, RLIMIT_NPROC # noqa: F401
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
self.skipTest(err) # RLIMIT_NPROC is specific to Linux and BSD
|
self.skipTest(err) # RLIMIT_NPROC is specific to Linux and BSD
|
||||||
code = """if 1:
|
code = """if 1:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Module docstring"""
|
"""Module docstring"""
|
||||||
|
|
||||||
# Test docstring extraction
|
# Test docstring extraction
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _ # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
# Empty docstring
|
# Empty docstring
|
||||||
|
|
|
@ -2516,7 +2516,7 @@ class SubinterpreterTests(unittest.TestCase):
|
||||||
from test.support import interpreters
|
from test.support import interpreters
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
raise unittest.SkipTest('subinterpreters required')
|
raise unittest.SkipTest('subinterpreters required')
|
||||||
import test.support.interpreters.channels
|
import test.support.interpreters.channels # noqa: F401
|
||||||
|
|
||||||
@cpython_only
|
@cpython_only
|
||||||
@no_rerun('channels (and queues) might have a refleak; see gh-122199')
|
@no_rerun('channels (and queues) might have a refleak; see gh-122199')
|
||||||
|
|
|
@ -46,11 +46,10 @@ import abc
|
||||||
import textwrap
|
import textwrap
|
||||||
import typing
|
import typing
|
||||||
import weakref
|
import weakref
|
||||||
import warnings
|
|
||||||
import types
|
import types
|
||||||
|
|
||||||
from test.support import (
|
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,
|
EqualToForwardRef,
|
||||||
)
|
)
|
||||||
from test.typinganndata import (
|
from test.typinganndata import (
|
||||||
|
|
|
@ -1008,7 +1008,7 @@ class EnsurePipTest(BaseTest):
|
||||||
err, flags=re.MULTILINE)
|
err, flags=re.MULTILINE)
|
||||||
# Ignore warning about missing optional module:
|
# Ignore warning about missing optional module:
|
||||||
try:
|
try:
|
||||||
import ssl
|
import ssl # noqa: F401
|
||||||
except ImportError:
|
except ImportError:
|
||||||
err = re.sub(
|
err = re.sub(
|
||||||
"^WARNING: Disabling truststore since ssl support is missing$",
|
"^WARNING: Disabling truststore since ssl support is missing$",
|
||||||
|
|
|
@ -6,7 +6,6 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import webbrowser
|
import webbrowser
|
||||||
from functools import partial
|
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
from test.support import is_apple_mobile
|
from test.support import is_apple_mobile
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from . import load_tests # noqa: F401
|
from . import load_tests
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -12,7 +12,6 @@ import threading
|
||||||
from test.support.import_helper import import_module
|
from test.support.import_helper import import_module
|
||||||
from test.support import threading_helper
|
from test.support import threading_helper
|
||||||
from test.support import _1M
|
from test.support import _1M
|
||||||
from test.support import Py_GIL_DISABLED
|
|
||||||
|
|
||||||
_zstd = import_module("_zstd")
|
_zstd = import_module("_zstd")
|
||||||
zstd = import_module("compression.zstd")
|
zstd = import_module("compression.zstd")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue