]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120417: Add #noqa to used imports in the stdlib (#120421)
authorVictor Stinner <vstinner@python.org>
Thu, 13 Jun 2024 14:14:50 +0000 (16:14 +0200)
committerGitHub <noreply@github.com>
Thu, 13 Jun 2024 14:14:50 +0000 (16:14 +0200)
Tools such as ruff can ignore "imported but unused" warnings if a
line ends with "# noqa: F401". It avoids the temptation to remove
an import which is used effectively.

25 files changed:
Lib/_pyio.py
Lib/code.py
Lib/codecs.py
Lib/collections/__init__.py
Lib/concurrent/futures/process.py
Lib/curses/__init__.py
Lib/datetime.py
Lib/decimal.py
Lib/hashlib.py
Lib/lzma.py
Lib/multiprocessing/context.py
Lib/multiprocessing/util.py
Lib/opcode.py
Lib/operator.py
Lib/platform.py
Lib/pstats.py
Lib/pydoc.py
Lib/re/_constants.py
Lib/site.py
Lib/sqlite3/__main__.py
Lib/struct.py
Lib/symtable.py
Lib/unittest/__init__.py
Lib/urllib/request.py
Lib/xml/dom/__init__.py

index a3fede699218a150fd6709ccb38c6e4e3c91cd9e..7d298e1674b49a373bca9d97f59672d7cdf1bc76 100644 (file)
@@ -16,7 +16,7 @@ else:
     _setmode = None
 
 import io
-from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END)
+from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END)  # noqa: F401
 
 valid_seek_flags = {0, 1, 2}  # Hardwired values
 if hasattr(os, 'SEEK_HOLE') :
index b93902ccf545b3443cc6cac6c24469c66aad3873..a55fced0704b1dc929c2e8318d8ad060c0070627 100644 (file)
@@ -355,7 +355,7 @@ def interact(banner=None, readfunc=None, local=None, exitmsg=None, local_exit=Fa
         console.raw_input = readfunc
     else:
         try:
-            import readline
+            import readline  # noqa: F401
         except ImportError:
             pass
     console.interact(banner, exitmsg)
index 9b35b6127dd01c77fc61f3f166c6985798b7359f..a887e5d4c94a38da2ab1717ae50fb1c57d054e1b 100644 (file)
@@ -1129,4 +1129,4 @@ except LookupError:
 # package
 _false = 0
 if _false:
-    import encodings
+    import encodings  # noqa: F401
index a17100e6c02a0e512dc451b12549dd83afd683d9..b47e728484c8acf800a7b257e8910ddc44411f4a 100644 (file)
@@ -46,7 +46,8 @@ else:
     _collections_abc.MutableSequence.register(deque)
 
 try:
-    from _collections import _deque_iterator
+    # Expose _deque_iterator to support pickling deque iterators
+    from _collections import _deque_iterator  # noqa: F401
 except ImportError:
     pass
 
index bb4892ebdfedf5c31fc3f882d0334a462aa01078..7092b4757b5429ff45eb38dd56eaee070ff35929 100644 (file)
@@ -589,7 +589,7 @@ def _check_system_limits():
             raise NotImplementedError(_system_limited)
     _system_limits_checked = True
     try:
-        import multiprocessing.synchronize
+        import multiprocessing.synchronize  # noqa: F401
     except ImportError:
         _system_limited = (
             "This Python build lacks multiprocessing.synchronize, usually due "
index 69270bfcd2b205b15436c920d57a01ac565d6efb..6165fe6c9875c00c144025d916d9e5d2d8807c54 100644 (file)
@@ -53,7 +53,7 @@ def start_color():
 try:
     has_key
 except NameError:
-    from .has_key import has_key
+    from .has_key import has_key  # noqa: F401
 
 # Wrapper for the entire curses-based application.  Runs a function which
 # should be the rest of your curses-based application.  If the application
index a33d2d724cb33d25ee591b7e39fb2129d3a4dd9a..b4f7bd045c7b684d04f6ad6cfbce88da2bad11ac 100644 (file)
@@ -1,9 +1,9 @@
 try:
     from _datetime import *
-    from _datetime import __doc__
+    from _datetime import __doc__  # noqa: F401
 except ImportError:
     from _pydatetime import *
-    from _pydatetime import __doc__
+    from _pydatetime import __doc__  # noqa: F401
 
 __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo",
            "MINYEAR", "MAXYEAR", "UTC")
index d61e374b9f999876e56571a99ab28c31f3171154..13a0dcb77f1267529361c23ccf19e56df157976c 100644 (file)
@@ -100,9 +100,9 @@ NaN
 
 try:
     from _decimal import *
-    from _decimal import __version__
-    from _decimal import __libmpdec_version__
+    from _decimal import __version__  # noqa: F401
+    from _decimal import __libmpdec_version__  # noqa: F401
 except ImportError:
     from _pydecimal import *
-    from _pydecimal import __version__
-    from _pydecimal import __libmpdec_version__
+    from _pydecimal import __version__  # noqa: F401
+    from _pydecimal import __libmpdec_version__  # noqa: F401
index 1b16441cb60ba7787b62ce6784656f6b9761409f..da0577023cf47da68c351cce02d93ccec38fe340 100644 (file)
@@ -187,7 +187,7 @@ except ImportError:
 
 try:
     # OpenSSL's scrypt requires OpenSSL 1.1+
-    from _hashlib import scrypt
+    from _hashlib import scrypt  # noqa: F401
 except ImportError:
     pass
 
index c1e3d33deb69a14bce9c4f70bc25f519c861521f..946066aa0fba56368b34810d05f3724faced1403 100644 (file)
@@ -25,7 +25,7 @@ import builtins
 import io
 import os
 from _lzma import *
-from _lzma import _encode_filter_properties, _decode_filter_properties
+from _lzma import _encode_filter_properties, _decode_filter_properties  # noqa: F401
 import _compression
 
 
index de8a264829dff3b5598501a3fa950918a2158fda..ddcc7e7900999e2b871b36d5480a519c119dbe48 100644 (file)
@@ -167,7 +167,7 @@ class BaseContext(object):
         '''
         # This is undocumented.  In previous versions of multiprocessing
         # its only effect was to make socket objects inheritable on Windows.
-        from . import connection
+        from . import connection  # noqa: F401
 
     def set_executable(self, executable):
         '''Sets the path to a python.exe or pythonw.exe binary used to run
index 75dde02d88c533563f43cfd464e9779cba7baf90..4f471fbde71ace24f57e53ebc8317a0f451266e4 100644 (file)
@@ -14,7 +14,7 @@ import weakref
 import atexit
 import threading        # we want threading to install it's
                         # cleanup function before multiprocessing does
-from subprocess import _args_from_interpreter_flags
+from subprocess import _args_from_interpreter_flags  # noqa: F401
 
 from . import process
 
index 85e37ff53e577ff47032c2dc447fe73c424014ad..85c0834c698ba28ef590d17a6b2092a18b4b02ab 100644 (file)
@@ -12,8 +12,8 @@ __all__ = ["cmp_op", "stack_effect", "hascompare", "opname", "opmap",
 import _opcode
 from _opcode import stack_effect
 
-from _opcode_metadata import (_specializations, _specialized_opmap, opmap,
-                              HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE)
+from _opcode_metadata import (_specializations, _specialized_opmap, opmap,  # noqa: F401
+                              HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE)  # noqa: F401
 EXTENDED_ARG = opmap['EXTENDED_ARG']
 
 opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
index 02ccdaa13ddb3183381e5114e00cab3051ff9671..6d2a762bc95b6d36bf5d2096a21ff09179e724ac 100644 (file)
@@ -415,7 +415,7 @@ try:
 except ImportError:
     pass
 else:
-    from _operator import __doc__
+    from _operator import __doc__  # noqa: F401
 
 # All of these "__func__ = func" assignments have to happen after importing
 # from _operator to make sure they're set to the right function
index a4fd2463f15a6c2cb6d5bdb129e272c37baa72de..d6322c9d99d2f3076a3f09d3c4d00a625800024e 100644 (file)
@@ -546,7 +546,7 @@ def java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', '')):
     warnings._deprecated('java_ver', remove=(3, 15))
     # Import the needed APIs
     try:
-        import java.lang
+        import java.lang  # noqa: F401
     except ImportError:
         return release, vendor, vminfo, osinfo
 
index 2f054bb4011e7f2576105a61458bab6bc430a86d..a174a545456e1a7dd60ccdd2ba28ec5c64eb90d1 100644 (file)
@@ -611,7 +611,7 @@ def f8(x):
 if __name__ == '__main__':
     import cmd
     try:
-        import readline
+        import readline  # noqa: F401
     except ImportError:
         pass
 
index 278e4846ebb71f4494cd2fb5c84cd0d6f1b0c3f4..be5cd9a80db710d62603fc045b7ae10a172e850d 100644 (file)
@@ -75,9 +75,12 @@ from collections import deque
 from reprlib import Repr
 from traceback import format_exception_only
 
-from _pyrepl.pager import (get_pager, plain, pipe_pager,
+from _pyrepl.pager import (get_pager, pipe_pager,
                            plain_pager, tempfile_pager, tty_pager)
 
+# Expose plain() as pydoc.plain()
+from _pyrepl.pager import plain  # noqa: F401
+
 
 # --------------------------------------------------------- old names
 
index 9c3c294ba448b416c6e06c1c41549906e7bb3098..4cb88c96d927151c644566559400431c56005773 100644 (file)
@@ -15,7 +15,7 @@
 
 MAGIC = 20230612
 
-from _sre import MAXREPEAT, MAXGROUPS
+from _sre import MAXREPEAT, MAXGROUPS  # noqa: F401
 
 # SRE standard exception (access as sre.error)
 # should this really be here?
index 7eace190f5ab21863cbca5bf76c2f859a1ccfc01..9381f6f510eb46d1e7d71a34ed1eec09a91a5e2a 100644 (file)
@@ -486,7 +486,7 @@ def register_readline():
     import atexit
     try:
         import readline
-        import rlcompleter
+        import rlcompleter  # noqa: F401
         import _pyrepl.readline
         import _pyrepl.unix_console
     except ImportError:
@@ -603,7 +603,7 @@ def execsitecustomize():
     """Run custom site specific code, if available."""
     try:
         try:
-            import sitecustomize
+            import sitecustomize  # noqa: F401
         except ImportError as exc:
             if exc.name == 'sitecustomize':
                 pass
@@ -623,7 +623,7 @@ def execusercustomize():
     """Run custom user specific code, if available."""
     try:
         try:
-            import usercustomize
+            import usercustomize  # noqa: F401
         except ImportError as exc:
             if exc.name == 'usercustomize':
                 pass
index b93b84384a092582455aedde0ea715bcb179dd24..d9423c25e3413588f14c288d3ed3170be6dd2092 100644 (file)
@@ -117,7 +117,7 @@ def main(*args):
             # No SQL provided; start the REPL.
             console = SqliteInteractiveConsole(con)
             try:
-                import readline
+                import readline  # noqa: F401
             except ImportError:
                 pass
             console.interact(banner, exitmsg="")
index d6bba58863649898a3f075cdda51cade9dc07f06..ff98e8c4cb3f1d423052e913546262ca618857e7 100644 (file)
@@ -11,5 +11,5 @@ __all__ = [
     ]
 
 from _struct import *
-from _struct import _clearcache
-from _struct import __doc__
+from _struct import _clearcache  # noqa: F401
+from _struct import __doc__  # noqa: F401
index d6ac1f527ba8ba00fab0c2eb81702e3771acb062..f8ba34964395352f10467697b642cee6a1b8823c 100644 (file)
@@ -3,9 +3,9 @@
 import _symtable
 from _symtable import (
     USE,
-    DEF_GLOBAL, DEF_NONLOCAL, DEF_LOCAL,
-    DEF_PARAM, DEF_TYPE_PARAM,
-    DEF_FREE_CLASS,
+    DEF_GLOBAL,  # noqa: F401
+    DEF_NONLOCAL, DEF_LOCAL,
+    DEF_PARAM, DEF_TYPE_PARAM, DEF_FREE_CLASS,
     DEF_IMPORT, DEF_BOUND, DEF_ANNOT,
     DEF_COMP_ITER, DEF_COMP_CELL,
     SCOPE_OFF, SCOPE_MASK,
index f1f6c911ef17d9673fea1ff6b948f21c140141c2..324e5d038aef03a8fed8414253d97468caceb32c 100644 (file)
@@ -57,9 +57,9 @@ from .result import TestResult
 from .case import (addModuleCleanup, TestCase, FunctionTestCase, SkipTest, skip,
                    skipIf, skipUnless, expectedFailure, doModuleCleanups,
                    enterModuleContext)
-from .suite import BaseTestSuite, TestSuite
+from .suite import BaseTestSuite, TestSuite  # noqa: F401
 from .loader import TestLoader, defaultTestLoader
-from .main import TestProgram, main
+from .main import TestProgram, main  # noqa: F401
 from .runner import TextTestRunner, TextTestResult
 from .signals import installHandler, registerResult, removeResult, removeHandler
 # IsolatedAsyncioTestCase will be imported lazily.
index ac6719ce854182476a0cfa164a8f6aad2901e516..58b0cb574a764a6561b59d7a57e28ef46d8537d8 100644 (file)
@@ -108,7 +108,7 @@ from urllib.response import addinfourl, addclosehook
 
 # check for SSL
 try:
-    import ssl
+    import ssl  # noqa: F401
 except ImportError:
     _have_ssl = False
 else:
index 97cf9a6429993d97e26e1867b038d433055cf419..dd7fb996afd616cfc811ea56a8d50345bf3ea7b6 100644 (file)
@@ -137,4 +137,4 @@ XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"
 EMPTY_NAMESPACE = None
 EMPTY_PREFIX = None
 
-from .domreg import getDOMImplementation, registerDOMImplementation
+from .domreg import getDOMImplementation, registerDOMImplementation  # noqa: F401