https://github.com/python/cpython/commit/6ae254aaa0a5a3985a52d1ab387a2b68c001bd96
commit: 6ae254aaa0a5a3985a52d1ab387a2b68c001bd96
branch: main
author: Victor Stinner <vstin...@python.org>
committer: vstinner <vstin...@python.org>
date: 2024-06-13T16:14:50+02:00
summary:

gh-120417: Add #noqa to used imports in the stdlib (#120421)

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.

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

diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index a3fede699218a1..7d298e1674b49a 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -16,7 +16,7 @@
     _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') :
diff --git a/Lib/code.py b/Lib/code.py
index b93902ccf545b3..a55fced0704b1d 100644
--- a/Lib/code.py
+++ b/Lib/code.py
@@ -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)
diff --git a/Lib/codecs.py b/Lib/codecs.py
index 9b35b6127dd01c..a887e5d4c94a38 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -1129,4 +1129,4 @@ def make_encoding_map(decoding_map):
 # package
 _false = 0
 if _false:
-    import encodings
+    import encodings  # noqa: F401
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index a17100e6c02a0e..b47e728484c8ac 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -46,7 +46,8 @@
     _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
 
diff --git a/Lib/concurrent/futures/process.py 
b/Lib/concurrent/futures/process.py
index bb4892ebdfedf5..7092b4757b5429 100644
--- a/Lib/concurrent/futures/process.py
+++ b/Lib/concurrent/futures/process.py
@@ -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 "
diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py
index 69270bfcd2b205..6165fe6c9875c0 100644
--- a/Lib/curses/__init__.py
+++ b/Lib/curses/__init__.py
@@ -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
diff --git a/Lib/datetime.py b/Lib/datetime.py
index a33d2d724cb33d..b4f7bd045c7b68 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -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")
diff --git a/Lib/decimal.py b/Lib/decimal.py
index d61e374b9f9998..13a0dcb77f1267 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -100,9 +100,9 @@
 
 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
diff --git a/Lib/hashlib.py b/Lib/hashlib.py
index 1b16441cb60ba7..da0577023cf47d 100644
--- a/Lib/hashlib.py
+++ b/Lib/hashlib.py
@@ -187,7 +187,7 @@ def __hash_new(name, data=b'', **kwargs):
 
 try:
     # OpenSSL's scrypt requires OpenSSL 1.1+
-    from _hashlib import scrypt
+    from _hashlib import scrypt  # noqa: F401
 except ImportError:
     pass
 
diff --git a/Lib/lzma.py b/Lib/lzma.py
index c1e3d33deb69a1..946066aa0fba56 100644
--- a/Lib/lzma.py
+++ b/Lib/lzma.py
@@ -25,7 +25,7 @@
 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
 
 
diff --git a/Lib/multiprocessing/context.py b/Lib/multiprocessing/context.py
index de8a264829dff3..ddcc7e7900999e 100644
--- a/Lib/multiprocessing/context.py
+++ b/Lib/multiprocessing/context.py
@@ -167,7 +167,7 @@ def allow_connection_pickling(self):
         '''
         # 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
diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py
index 75dde02d88c533..4f471fbde71ace 100644
--- a/Lib/multiprocessing/util.py
+++ b/Lib/multiprocessing/util.py
@@ -14,7 +14,7 @@
 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
 
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 85e37ff53e577f..85c0834c698ba2 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -12,8 +12,8 @@
 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)]
diff --git a/Lib/operator.py b/Lib/operator.py
index 02ccdaa13ddb31..6d2a762bc95b6d 100644
--- a/Lib/operator.py
+++ b/Lib/operator.py
@@ -415,7 +415,7 @@ def ixor(a, b):
 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
diff --git a/Lib/platform.py b/Lib/platform.py
index a4fd2463f15a6c..d6322c9d99d2f3 100644
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -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
 
diff --git a/Lib/pstats.py b/Lib/pstats.py
index 2f054bb4011e7f..a174a545456e1a 100644
--- a/Lib/pstats.py
+++ b/Lib/pstats.py
@@ -611,7 +611,7 @@ def f8(x):
 if __name__ == '__main__':
     import cmd
     try:
-        import readline
+        import readline  # noqa: F401
     except ImportError:
         pass
 
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 278e4846ebb71f..be5cd9a80db710 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -75,9 +75,12 @@ class or function within a module or module in a package.  
If the
 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
 
diff --git a/Lib/re/_constants.py b/Lib/re/_constants.py
index 9c3c294ba448b4..4cb88c96d92715 100644
--- a/Lib/re/_constants.py
+++ b/Lib/re/_constants.py
@@ -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?
diff --git a/Lib/site.py b/Lib/site.py
index 7eace190f5ab21..9381f6f510eb46 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -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
diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py
index b93b84384a0925..d9423c25e34135 100644
--- a/Lib/sqlite3/__main__.py
+++ b/Lib/sqlite3/__main__.py
@@ -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="")
diff --git a/Lib/struct.py b/Lib/struct.py
index d6bba588636498..ff98e8c4cb3f1d 100644
--- a/Lib/struct.py
+++ b/Lib/struct.py
@@ -11,5 +11,5 @@
     ]
 
 from _struct import *
-from _struct import _clearcache
-from _struct import __doc__
+from _struct import _clearcache  # noqa: F401
+from _struct import __doc__  # noqa: F401
diff --git a/Lib/symtable.py b/Lib/symtable.py
index d6ac1f527ba8ba..f8ba3496439535 100644
--- a/Lib/symtable.py
+++ b/Lib/symtable.py
@@ -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,
diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py
index f1f6c911ef17d9..324e5d038aef03 100644
--- a/Lib/unittest/__init__.py
+++ b/Lib/unittest/__init__.py
@@ -57,9 +57,9 @@ def testMultiply(self):
 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.
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index ac6719ce854182..58b0cb574a764a 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -108,7 +108,7 @@
 
 # check for SSL
 try:
-    import ssl
+    import ssl  # noqa: F401
 except ImportError:
     _have_ssl = False
 else:
diff --git a/Lib/xml/dom/__init__.py b/Lib/xml/dom/__init__.py
index 97cf9a6429993d..dd7fb996afd616 100644
--- a/Lib/xml/dom/__init__.py
+++ b/Lib/xml/dom/__init__.py
@@ -137,4 +137,4 @@ class UserDataHandler:
 EMPTY_NAMESPACE = None
 EMPTY_PREFIX = None
 
-from .domreg import getDOMImplementation, registerDOMImplementation
+from .domreg import getDOMImplementation, registerDOMImplementation  # noqa: 
F401

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to