8000 gh-120417: Add #noqa: F401 to tests · python/cpython@9684aa1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9684aa1

Browse files
committed
gh-120417: Add #noqa: F401 to tests
Ignore linter "imported but unused" warnings in tests when the linter doesn't understand why the import is important.
1 parent f869bcf commit 9684aa1

24 files changed

+43
-41
lines changed

Lib/test/support/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,8 @@ def refcount_test(test):
12211221

12221222
def requires_limited_api(test):
12231223
try:
1224-
import _testcapi
1225-
import _testlimitedcapi
1224+
import _testcapi # noqa: F401
1225+
import _testlimitedcapi # noqa: F401
12261226
except ImportError:
12271227
return unittest.skip('needs _testcapi and _testlimitedcapi modules')(test)
12281228
return test
@@ -2299,7 +2299,7 @@ def clear_ignored_deprecations(*tokens: object) -> None:
22992299
def requires_venv_with_pip():
23002300
# ensurepip requires zlib to open ZIP archives (.whl binary wheel packages)
23012301
try:
2302-
import zlib
2302+
import zlib # noqa: F401
23032303
except ImportError:
23042304
return unittest.skipIf(True, "venv: ensurepip requires zlib")
23052305

Lib/test/test___all__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_all(self):
103103
# In case _socket fails to build, make this test fail more gracefully
104104
# than an AttributeError somewhere deep in concurrent.futures, email
105105
# or unittest.
106-
import _socket
106+
import _socket # noqa: F401
107107

108108
ignored = []
109109
failed_imports = []

Lib/test/test_asyncio/test_tasks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,14 +3103,14 @@ def test_asyncio_module_compiled(self):
31033103
# fail on systems where C modules were successfully compiled
31043104
# (hence the test for _functools etc), but _asyncio somehow didn't.
31053105
try:
3106-
import _functools
3107-
import _json
3108-
import _pickle
3106+
import _functools # noqa: F401
3107+
import _json # noqa: F401
3108+
import _pickle # noqa: F401
31093109
except ImportError:
31103110
self.skipTest('C modules are not available')
31113111
else:
31123112
try:
3113-
import _asyncio
3113+
import _asyncio # noqa: F401
31143114
except ImportError:
31153115
self.fail('_asyncio module is missing')
31163116

Lib/test/test_capi/check_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def import_singlephase():
1111
assert '_testsinglephase' not in sys.modules
1212
try:
13-
import _testsinglephase
13+
import _testsinglephase # noqa: F401
1414
except ImportError:
1515
sys.modules.pop('_testsinglephase', None)
1616
return False

Lib/test/test_cmd_line.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def test_xdev(self):
737737

738738
# Memory allocator debug hooks
739739
try:
740-
import _testinternalcapi
740+
import _testinternalcapi # noqa: F401
741741
except ImportError:
742742
pass
743743
else:
@@ -754,7 +754,7 @@ def test_xdev(self):
754754

755755
# Faulthandler
756756
try:
757-
import faulthandler
757+
import faulthandler # noqa: F401
758758
except ImportError:
759759
pass
760760
else:

Lib/test/test_codecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,7 @@ def test_seek0(self):
29582958
bytes_transform_encodings.append("zlib_codec")
29592959
transform_aliases["zlib_codec"] = ["zip", "zlib"]
29602960
try:
2961-
import bz2
2961+
import bz2 # noqa: F401
29622962
except ImportError:
29632963
pass
29642964
else:

Lib/test/test_compile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ class A:
441441
def f():
442442
__mangled = 1
443443
__not_mangled__ = 2
444-
import __mangled_mod
445-
import __package__.module
444+
import __mangled_mod # noqa: F401
445+
import __package__.module # noqa: F401
446446

447447
self.assertIn("_A__mangled", A.f.__code__.co_varnames)
448448
self.assertIn("__not_mangled__", A.f.__code__.co_varnames)

Lib/test/test_compileall.py

Lines changed: 1 addition & 1 deletion
< 10000 div data-testid="addition diffstat" class="DiffSquares-module__diffSquare--h5kjy DiffSquares-module__addition--jeNtt">
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# compileall relies on ProcessPoolExecutor if ProcessPoolExecutor exists
1919
# and it can function.
2020
from multiprocessing.util import _cleanup_tests as multiprocessing_cleanup_tests
21-
from concurrent.futures import ProcessPoolExecutor
21+
from concurrent.futures import ProcessPoolExecutor # noqa: F401
2222
from concurrent.futures.process import _check_system_limits
2323
_check_system_limits()
2424
_have_multiprocessing = True

Lib/test/test_descrtut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# of much interest anymore), and a few were fiddled to make the output
99
# deterministic.
1010

11-
from test.support import sortdict
11+
from test.support import sortdict # noqa: F401
1212
import doctest
1313
import unittest
1414

Lib/test/test_file_eintr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
raise unittest.SkipTest("test module requires subprocess")
2222

2323
# Test import all of the things we're about to try testing up front.
24-
import _io
25-
import _pyio
24+
import _io # noqa: F401
25+
import _pyio # noqa: F401
2626

2727
@unittest.skipUnless(os.name == 'posix', 'tests requires a posix system.')
2828
class TestFileIOSignalInterrupt:

Lib/test/test_future_stmt/nested_scope.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""This is a test"""
22

3-
from __future__ import nested_scopes; import site
3+
from __future__ import nested_scopes; import site # noqa: F401
44

55
def f(x):
66
def g(y):

Lib/test/test_future_stmt/test_future.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ def test_future_single_import(self):
6767
with import_helper.CleanImport(
6868
'test.test_future_stmt.test_future_single_import',
6969
):
70-
from test.test_future_stmt import test_future_single_import
70+
from test.test_future_stmt import test_future_single_import # noqa: F401
7171

7272
def test_future_multiple_imports(self):
7373
with import_helper.CleanImport(
7474
'test.test_future_stmt.test_future_multiple_imports',
7575
):
76-
from test.test_future_stmt import test_future_multiple_imports
76+
from test.test_future_stmt import test_future_multiple_imports # noqa: F401
7777

7878
def test_future_multiple_features(self):
7979
with import_helper.CleanImport(
8080
"test.test_future_stmt.test_future_multiple_features",
8181
):
82-
from test.test_future_stmt import test_future_multiple_features
82+
from test.test_future_stmt import test_future_multiple_features # noqa: F401
8383

8484
def test_unknown_future_flag(self):
8585
code = """
@@ -153,7 +153,7 @@ def test_future_import_braces(self):
153153

154154
def test_module_with_future_import_not_on_top(self):
155155
with self.assertRaises(SyntaxError) as cm:
156-
from test.test_future_stmt import badsyntax_future
156+
from test.test_future_stmt import badsyntax_future # noqa: F401
157157
self.check_syntax_error(cm.exception, "badsyntax_future", lineno=3)
158158

159159
def test_ensure_flags_dont_clash(self):

Lib/test/test_inspect/test_inspect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ def test_getfullargspec_builtin_func_no_signature(self):
12871287
(dict.__class_getitem__, meth_type_o),
12881288
]
12891289
try:
1290-
import _stat
1290+
import _stat # noqa: F401
12911291
except ImportError:
12921292
# if the _stat extension is not available, stat.S_IMODE() is
12931293
# implemented in Python, not in C
@@ -3303,7 +3303,7 @@ def test_signature_on_builtins_no_signature(self):
33033303
(dict.__class_getitem__, meth_o),
33043304
]
33053305
try:
3306-
import _stat
3306+
import _stat # noqa: F401
33073307
except ImportError:
33083308
# if the _stat extension is not available, stat.S_IMODE() is
33093309
# implemented in Python, not in C

Lib/test/test_pkg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def mkhier(self, descr):
9494
def test_1(self):
9595
hier = [("t1", None), ("t1 __init__.py", "")]
9696
self.mkhier(hier)
97-
import t1
97+
import t1 # noqa: F401
9898

9999
def test_2(self):
100100
hier = [
@@ -124,7 +124,7 @@ def test_2(self):
124124

125125
from t2 import sub
126126
from t2.sub import subsub
127-
from t2.sub.subsub import spam
127+
from t2.sub.subsub import spam # noqa: F401
128128
self.assertEqual(sub.__name__, "t2.sub")
129129
self.assertEqual(subsub.__name__, "t2.sub.subsub")
130130
self.assertEqual(sub.< 10000 span class=pl-c1>subsub.__name__, "t2.sub.subsub")

Lib/test/test_pydoc/test_pydoc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,8 @@ def test_url_search_package_error(self):
12391239
sys.path.insert(0, TESTFN)
12401240
try:
12411241
with self.assertRaisesRegex(ValueError, "ouch"):
1242-
import test_error_package # Sanity check
1242+
# Sanity check
1243+
import test_error_package # noqa: F401
12431244

12441245
text = self.call_url_handler("search?key=test_error_package",
12451246
"Pydoc: Search Results")

Lib/test/test_re.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# some platforms lack working multiprocessing
1515
try:
16-
import _multiprocessing
16+
import _multiprocessing # noqa: F401
1717
except ImportError:
1818
multiprocessing = None
1919
else:
@@ -1228,7 +1228,7 @@ def test_pickling(self):
12281228
newpat = pickle.loads(pickled)
12291229
self.assertEqual(newpat, oldpat)
12301230
# current pickle expects the _compile() reconstructor in re module
1231-
from re import _compile
1231+
from re import _compile # noqa: F401
12321232

12331233
def test_copying(self):
12341234
import copy

Lib/test/test_site.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def test_sitecustomize_executed(self):
513513
# If sitecustomize is available, it should have been imported.
514514
if "sitecustomize" not in sys.modules:
515515
try:
516-
import sitecustomize
516+
import sitecustomize # noqa: F401
517517
except ImportError:
518518
pass
519519
else:

Lib/test/test_sundry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ def test_untested_modules_can_be_imported(self):
1818
self.fail('{} has tests even though test_sundry claims '
1919
'otherwise'.format(name))
2020

21-
import html.entities
21+
import html.entities # noqa: F401
2222

2323
try:
24-
import tty # Not available on Windows
24+
# Not available on Windows
25+
import tty # noqa: F401
2526
except ImportError:
2627
if support.verbose:
2728
print("skipping tty")

Lib/test/test_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_get_original_stdout(self):
7070
self.assertEqual(support.get_original_stdout(), sys.stdout)
7171

7272
def test_unload(self):
73-
import sched
73+
import sched # noqa: F401
7474
self.assertIn("sched", sys.modules)
7575
import_helper.unload("sched")
7676
self.assertNotIn("sched", sys.modules)

Lib/test/test_unicode_identifiers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_non_bmp_normalized(self):
1919

2020
def test_invalid(self):
2121
try:
22-
from test.tokenizedata import badsyntax_3131
22+
from test.tokenizedata import badsyntax_3131 # noqa: F401
2323
except SyntaxError as err:
2424
self.assertEqual(str(err),
2525
"invalid character '€' (U+20AC) (badsyntax_3131.py, line 2)")

Lib/test/test_utf8source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_pep3120(self):
1414

1515
def test_badsyntax(self):
1616
try:
17-
import test.tokenizedata.badsyntax_pep3120
17+
import test.tokenizedata.badsyntax_pep3120 # noqa: F401
1818
except SyntaxError as msg:
1919
msg = str(msg).lower()
2020
self.assertTrue('utf-8' in msg)

Lib/test/test_warnings/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def test_stacklevel_import(self):
499499
with original_warnings.catch_warnings(record=True,
500500
module=self.module) as w:
501501
self.module.simplefilter('always')
502-
import test.test_warnings.data.import_warning
502+
import test.test_warnings.data.import_warning # noqa: F401
503503
self.assertEqual(len(w), 1)
504504
self.assertEqual(w[0].filename, __file__)
505505

Lib/test/test_xml_etree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ class ModuleTest(unittest.TestCase):
138138
def test_sanity(self):
139139
# Import sanity.
140140

141-
from xml.etree import ElementTree
142-
from xml.etree import ElementInclude
143-
from xml.etree import ElementPath
141+
from xml.etree import ElementTree # noqa: F401
142+
from xml.etree import ElementInclude # noqa: F401
143+
from xml.etree import ElementPath # noqa: F401
144144

145145
def test_all(self):
146146
names = ("xml.etree.ElementTree", "_elementtree")

Lib/test/test_xmlrpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def test_get_host_info(self):
308308

309309
def test_ssl_presence(self):
310310
try:
311-
import ssl
311+
import ssl # noqa: F401
312312
except ImportError:
313313
has_ssl = False
314314
else:

0 commit comments

Comments
 (0)
0