]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120417: Add #noqa: F401 to tests (#120627)
authorVictor Stinner <vstinner@python.org>
Tue, 18 Jun 2024 15:51:47 +0000 (17:51 +0200)
committerGitHub <noreply@github.com>
Tue, 18 Jun 2024 15:51:47 +0000 (15:51 +0000)
Ignore linter "imported but unused" warnings in tests when the linter
doesn't understand how the import is used.

24 files changed:
Lib/test/support/__init__.py
Lib/test/test___all__.py
Lib/test/test_asyncio/test_tasks.py
Lib/test/test_capi/check_config.py
Lib/test/test_cmd_line.py
Lib/test/test_codecs.py
Lib/test/test_compile.py
Lib/test/test_compileall.py
Lib/test/test_descrtut.py
Lib/test/test_file_eintr.py
Lib/test/test_future_stmt/nested_scope.py
Lib/test/test_future_stmt/test_future.py
Lib/test/test_inspect/test_inspect.py
Lib/test/test_pkg.py
Lib/test/test_pydoc/test_pydoc.py
Lib/test/test_re.py
Lib/test/test_site.py
Lib/test/test_sundry.py
Lib/test/test_support.py
Lib/test/test_unicode_identifiers.py
Lib/test/test_utf8source.py
Lib/test/test_warnings/__init__.py
Lib/test/test_xml_etree.py
Lib/test/test_xmlrpc.py

index a045c88d7f4af08ce39ba8ca36d67fcfd895f346..4b430f85e7175cd744e45d998ad43cb29b2c1757 100644 (file)
@@ -1221,8 +1221,8 @@ def refcount_test(test):
 
 def requires_limited_api(test):
     try:
-        import _testcapi
-        import _testlimitedcapi
+        import _testcapi  # noqa: F401
+        import _testlimitedcapi  # noqa: F401
     except ImportError:
         return unittest.skip('needs _testcapi and _testlimitedcapi modules')(test)
     return test
@@ -2299,7 +2299,7 @@ def clear_ignored_deprecations(*tokens: object) -> None:
 def requires_venv_with_pip():
     # ensurepip requires zlib to open ZIP archives (.whl binary wheel packages)
     try:
-        import zlib
+        import zlib  # noqa: F401
     except ImportError:
         return unittest.skipIf(True, "venv: ensurepip requires zlib")
 
index b40622efe4611ec8c10d61fe967164c37bc2f126..e405056c8ffcb5c5fa7f198b333ff2e97a481bde 100644 (file)
@@ -103,7 +103,7 @@ class AllTest(unittest.TestCase):
         # In case _socket fails to build, make this test fail more gracefully
         # than an AttributeError somewhere deep in concurrent.futures, email
         # or unittest.
-        import _socket
+        import _socket  # noqa: F401
 
         ignored = []
         failed_imports = []
index 5b09c81faef62a83ba349086ed151682d45f3099..cc0d7f52a1bf4cddced1ddc626a45794cc2a2a41 100644 (file)
@@ -3103,14 +3103,14 @@ class GenericTaskTests(test_utils.TestCase):
         # fail on systems where C modules were successfully compiled
         # (hence the test for _functools etc), but _asyncio somehow didn't.
         try:
-            import _functools
-            import _json
-            import _pickle
+            import _functools  # noqa: F401
+            import _json       # noqa: F401
+            import _pickle     # noqa: F401
         except ImportError:
             self.skipTest('C modules are not available')
         else:
             try:
-                import _asyncio
+                import _asyncio  # noqa: F401
             except ImportError:
                 self.fail('_asyncio module is missing')
 
index eb99ae16f2b69ec35c7524813cd524a0cb111977..bc4f3a0beb9c1e5145976f5ebd2583ac94628cc0 100644 (file)
@@ -10,7 +10,7 @@ import sys
 def import_singlephase():
     assert '_testsinglephase' not in sys.modules
     try:
-        import _testsinglephase
+        import _testsinglephase  # noqa: F401
     except ImportError:
         sys.modules.pop('_testsinglephase', None)
         return False
index 058470082fbbf0130a5037bc19e0e2cedee6327b..8418da541fde8c4095e15c2559b00e7e24b9e994 100644 (file)
@@ -737,7 +737,7 @@ class CmdLineTest(unittest.TestCase):
 
         # Memory allocator debug hooks
         try:
-            import _testinternalcapi
+            import _testinternalcapi  # noqa: F401
         except ImportError:
             pass
         else:
@@ -754,7 +754,7 @@ class CmdLineTest(unittest.TestCase):
 
         # Faulthandler
         try:
-            import faulthandler
+            import faulthandler  # noqa: F401
         except ImportError:
             pass
         else:
index e05b95c2d60bade83dfefc576cf9e4bd7ee3f3d5..428036e1765b8f4ed0f69ce25833ac03644bcc67 100644 (file)
@@ -2958,7 +2958,7 @@ else:
     bytes_transform_encodings.append("zlib_codec")
     transform_aliases["zlib_codec"] = ["zip", "zlib"]
 try:
-    import bz2
+    import bz2  # noqa: F401
 except ImportError:
     pass
 else:
index 219314b5ce3d6f23faaf4ba0817ec46451c4f915..40295236eb7d92b681dbb99e1809de2011964216 100644 (file)
@@ -441,8 +441,8 @@ class TestSpecifics(unittest.TestCase):
             def f():
                 __mangled = 1
                 __not_mangled__ = 2
-                import __mangled_mod
-                import __package__.module
+                import __mangled_mod       # noqa: F401
+                import __package__.module  # noqa: F401
 
         self.assertIn("_A__mangled", A.f.__code__.co_varnames)
         self.assertIn("__not_mangled__", A.f.__code__.co_varnames)
index 812ff5e7f84461ea9a93421bc8ba7cefe54efcf8..3a34c6822bc07931ddca924550708a0342a617c2 100644 (file)
@@ -18,7 +18,7 @@ try:
     # compileall relies on ProcessPoolExecutor if ProcessPoolExecutor exists
     # and it can function.
     from multiprocessing.util import _cleanup_tests as multiprocessing_cleanup_tests
-    from concurrent.futures import ProcessPoolExecutor
+    from concurrent.futures import ProcessPoolExecutor  # noqa: F401
     from concurrent.futures.process import _check_system_limits
     _check_system_limits()
     _have_multiprocessing = True
index f097c4e7300baacf9c51b9b6febe878fa6482e5e..828440a993a975d155c941332b63c9738411e494 100644 (file)
@@ -8,7 +8,7 @@
 # of much interest anymore), and a few were fiddled to make the output
 # deterministic.
 
-from test.support import sortdict
+from test.support import sortdict  # noqa: F401
 import doctest
 import unittest
 
index f9236f45ca4be84403533efd238a82eb486f90a5..466f94e389f986ce49f973053591bb3d1674d874 100644 (file)
@@ -21,8 +21,8 @@ if not support.has_subprocess_support:
     raise unittest.SkipTest("test module requires subprocess")
 
 # Test import all of the things we're about to try testing up front.
-import _io
-import _pyio
+import _io    # noqa: F401
+import _pyio  # noqa: F401
 
 @unittest.skipUnless(os.name == 'posix', 'tests requires a posix system.')
 class TestFileIOSignalInterrupt:
index 3d7fc860a3765545bdb3b2ff9ffa24c767721f26..a8433a42cbb6b0a28ea14482b624427a46d3bba1 100644 (file)
@@ -1,6 +1,6 @@
 """This is a test"""
 
-from __future__ import nested_scopes; import site
+from __future__ import nested_scopes; import site  # noqa: F401
 
 def f(x):
     def g(y):
index bb31d0a0023fad0a73700b2296d132874ee53c62..44512e0101dac00c8fde1d0df00b609e1529b607 100644 (file)
@@ -67,19 +67,19 @@ class FutureTest(unittest.TestCase):
         with import_helper.CleanImport(
             'test.test_future_stmt.test_future_single_import',
         ):
-            from test.test_future_stmt import test_future_single_import
+            from test.test_future_stmt import test_future_single_import  # noqa: F401
 
     def test_future_multiple_imports(self):
         with import_helper.CleanImport(
             'test.test_future_stmt.test_future_multiple_imports',
         ):
-            from test.test_future_stmt import test_future_multiple_imports
+            from test.test_future_stmt import test_future_multiple_imports  # noqa: F401
 
     def test_future_multiple_features(self):
         with import_helper.CleanImport(
             "test.test_future_stmt.test_future_multiple_features",
         ):
-            from test.test_future_stmt import test_future_multiple_features
+            from test.test_future_stmt import test_future_multiple_features  # noqa: F401
 
     def test_unknown_future_flag(self):
         code = """
@@ -153,7 +153,7 @@ class FutureTest(unittest.TestCase):
 
     def test_module_with_future_import_not_on_top(self):
         with self.assertRaises(SyntaxError) as cm:
-            from test.test_future_stmt import badsyntax_future
+            from test.test_future_stmt import badsyntax_future  # noqa: F401
         self.check_syntax_error(cm.exception, "badsyntax_future", lineno=3)
 
     def test_ensure_flags_dont_clash(self):
index 88835cd79aad7fe6a020c142068d518ec09c0ff9..1ade4bbdd53e6719ab50437d1ee2b4dba82aeb13 100644 (file)
@@ -1287,7 +1287,7 @@ class TestClassesAndFunctions(unittest.TestCase):
             (dict.__class_getitem__, meth_type_o),
         ]
         try:
-            import _stat
+            import _stat  # noqa: F401
         except ImportError:
             # if the _stat extension is not available, stat.S_IMODE() is
             # implemented in Python, not in C
@@ -3303,7 +3303,7 @@ class TestSignatureObject(unittest.TestCase):
             (dict.__class_getitem__, meth_o),
         ]
         try:
-            import _stat
+            import _stat  # noqa: F401
         except ImportError:
             # if the _stat extension is not available, stat.S_IMODE() is
             # implemented in Python, not in C
index eed0fd1c6b73fa14f58794bc1a2fde7285c597b0..a7a1c2affbe1fb31079465d7124da531bfcb2563 100644 (file)
@@ -94,7 +94,7 @@ class TestPkg(unittest.TestCase):
     def test_1(self):
         hier = [("t1", None), ("t1 __init__.py", "")]
         self.mkhier(hier)
-        import t1
+        import t1  # noqa: F401
 
     def test_2(self):
         hier = [
@@ -124,7 +124,7 @@ class TestPkg(unittest.TestCase):
 
         from t2 import sub
         from t2.sub import subsub
-        from t2.sub.subsub import spam
+        from t2.sub.subsub import spam  # noqa: F401
         self.assertEqual(sub.__name__, "t2.sub")
         self.assertEqual(subsub.__name__, "t2.sub.subsub")
         self.assertEqual(sub.subsub.__name__, "t2.sub.subsub")
index bffebf38e1f9b2d3515da16804a0662d01330052..40b3aca25e0da874f563f6ac625b8a40cc2b107d 100644 (file)
@@ -1239,7 +1239,8 @@ class PydocImportTest(PydocBaseTest):
             sys.path.insert(0, TESTFN)
             try:
                 with self.assertRaisesRegex(ValueError, "ouch"):
-                    import test_error_package  # Sanity check
+                    # Sanity check
+                    import test_error_package  # noqa: F401
 
                 text = self.call_url_handler("search?key=test_error_package",
                     "Pydoc: Search Results")
index d8c839da3d294608c4103e09def53481151c0b93..1f2ab6028b588e28dbf9e8383d8b977e42b21ac8 100644 (file)
@@ -13,7 +13,7 @@ from weakref import proxy
 
 # some platforms lack working multiprocessing
 try:
-    import _multiprocessing
+    import _multiprocessing  # noqa: F401
 except ImportError:
     multiprocessing = None
 else:
@@ -1228,7 +1228,7 @@ class ReTests(unittest.TestCase):
             newpat = pickle.loads(pickled)
             self.assertEqual(newpat, oldpat)
         # current pickle expects the _compile() reconstructor in re module
-        from re import _compile
+        from re import _compile  # noqa: F401
 
     def test_copying(self):
         import copy
index 0502181854f52b5b5dbe01029e455f6985b7a785..bcdc232c7120710cea121e213b0886b02f5e337a 100644 (file)
@@ -513,7 +513,7 @@ class ImportSideEffectTests(unittest.TestCase):
         # If sitecustomize is available, it should have been imported.
         if "sitecustomize" not in sys.modules:
             try:
-                import sitecustomize
+                import sitecustomize  # noqa: F401
             except ImportError:
                 pass
             else:
index f4a8d434ed1b8c9dabfece8dde725c007ad98de9..d6d08ee53f821cfd5fbd0a30ffd9d34f7dd91598 100644 (file)
@@ -18,10 +18,11 @@ class TestUntestedModules(unittest.TestCase):
                     self.fail('{} has tests even though test_sundry claims '
                               'otherwise'.format(name))
 
-            import html.entities
+            import html.entities  # noqa: F401
 
             try:
-                import tty  # Not available on Windows
+                # Not available on Windows
+                import tty  # noqa: F401
             except ImportError:
                 if support.verbose:
                     print("skipping tty")
index d160cbf0645b47f05b884662660a51fb2bc715e1..d6f024a476920c44a1a1ba33e48fd213be2c9971 100644 (file)
@@ -70,7 +70,7 @@ class TestSupport(unittest.TestCase):
         self.assertEqual(support.get_original_stdout(), sys.stdout)
 
     def test_unload(self):
-        import sched
+        import sched  # noqa: F401
         self.assertIn("sched", sys.modules)
         import_helper.unload("sched")
         self.assertNotIn("sched", sys.modules)
index 63c6c055824b20f1428bea3a066984271c64b031..3680072d6437921b21ad33a28de1cc49ae2e7a90 100644 (file)
@@ -19,7 +19,7 @@ class PEP3131Test(unittest.TestCase):
 
     def test_invalid(self):
         try:
-            from test.tokenizedata import badsyntax_3131
+            from test.tokenizedata import badsyntax_3131  # noqa: F401
         except SyntaxError as err:
             self.assertEqual(str(err),
               "invalid character '€' (U+20AC) (badsyntax_3131.py, line 2)")
index c42b6aaaab579d45ffa5a15abd2e430332b14639..7336cf00a71183c635509aafe40a402284c50262 100644 (file)
@@ -14,7 +14,7 @@ class PEP3120Test(unittest.TestCase):
 
     def test_badsyntax(self):
         try:
-            import test.tokenizedata.badsyntax_pep3120
+            import test.tokenizedata.badsyntax_pep3120  # noqa: F401
         except SyntaxError as msg:
             msg = str(msg).lower()
             self.assertTrue('utf-8' in msg)
index 4416ed0f3ed3ef98f861e3f66079af8a7f1f60e9..36618d509fafe1c81579dfae065da101b1030e25 100644 (file)
@@ -499,7 +499,7 @@ class WarnTests(BaseTest):
             with original_warnings.catch_warnings(record=True,
                     module=self.module) as w:
                 self.module.simplefilter('always')
-                import test.test_warnings.data.import_warning
+                import test.test_warnings.data.import_warning  # noqa: F401
                 self.assertEqual(len(w), 1)
                 self.assertEqual(w[0].filename, __file__)
 
index 3d9141fea1ef3e43540b6be245545fc3c44321a6..930501633d1f3823a557dccb2dd09f0055ebf341 100644 (file)
@@ -138,9 +138,9 @@ class ModuleTest(unittest.TestCase):
     def test_sanity(self):
         # Import sanity.
 
-        from xml.etree import ElementTree
-        from xml.etree import ElementInclude
-        from xml.etree import ElementPath
+        from xml.etree import ElementTree     # noqa: F401
+        from xml.etree import ElementInclude  # noqa: F401
+        from xml.etree import ElementPath     # noqa: F401
 
     def test_all(self):
         names = ("xml.etree.ElementTree", "_elementtree")
index 6c4b8384a3202e95606d1cc04c59e8b918725e37..2803c6d45c27bfaa9e7a0aece54d7fc962a2a9bd 100644 (file)
@@ -308,7 +308,7 @@ class XMLRPCTestCase(unittest.TestCase):
 
     def test_ssl_presence(self):
         try:
-            import ssl
+            import ssl  # noqa: F401
         except ImportError:
             has_ssl = False
         else: