From 8347c30f185ff3fd4862fb679977bba6cedf1095 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 12 Jun 2024 18:11:56 +0200 Subject: [PATCH 1/8] gh-120417: Add #noqa to used imports in the stdlib Tools such as ruff can ignore "imported but unused" warnings if a line ends with "# noqa". It avoids the temptation to remove an import which is used effectively. --- Lib/_pyio.py | 2 +- Lib/code.py | 2 +- Lib/codecs.py | 2 +- Lib/datetime.py | 4 ++-- Lib/decimal.py | 8 ++++---- Lib/hashlib.py | 2 +- Lib/lzma.py | 2 +- Lib/opcode.py | 4 ++-- Lib/operator.py | 2 +- Lib/platform.py | 2 +- Lib/pstats.py | 2 +- Lib/pydoc.py | 5 +++-- Lib/site.py | 12 ++++++------ Lib/ssl.py | 20 ++++++++++---------- Lib/struct.py | 4 ++-- Lib/subprocess.py | 20 ++++++++++---------- Lib/symtable.py | 6 +++--- 17 files changed, 50 insertions(+), 49 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index a3fede699218a1..2abdace8dc950d 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 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..ef3261128cda16 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 except ImportError: pass console.interact(banner, exitmsg) diff --git a/Lib/codecs.py b/Lib/codecs.py index 9b35b6127dd01c..56d3379577181e 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 diff --git a/Lib/datetime.py b/Lib/datetime.py index a33d2d724cb33d..b9e8599f808268 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 except ImportError: from _pydatetime import * - from _pydatetime import __doc__ + from _pydatetime import __doc__ # noqa __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC") diff --git a/Lib/decimal.py b/Lib/decimal.py index d61e374b9f9998..70a890fd86b74f 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 + from _decimal import __libmpdec_version__ # noqa except ImportError: from _pydecimal import * - from _pydecimal import __version__ - from _pydecimal import __libmpdec_version__ + from _pydecimal import __version__ # noqa + from _pydecimal import __libmpdec_version__ # noqa diff --git a/Lib/hashlib.py b/Lib/hashlib.py index 1b16441cb60ba7..5c2fa55235f950 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 except ImportError: pass diff --git a/Lib/lzma.py b/Lib/lzma.py index c1e3d33deb69a1..034805edeee919 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 import _compression diff --git a/Lib/opcode.py b/Lib/opcode.py index 85e37ff53e577f..21ef4aca8bd4e3 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 + HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE) # noqa 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..1f685624763c2f 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 # 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..ad1f147aebd47b 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 except ImportError: return release, vendor, vminfo, osinfo diff --git a/Lib/pstats.py b/Lib/pstats.py index 2f054bb4011e7f..08c5321ee4ac2f 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 except ImportError: pass diff --git a/Lib/pydoc.py b/Lib/pydoc.py index d7579c1cc3dcd1..3b9ac855532d4b 100644 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -75,8 +75,9 @@ 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, escape_less, pipe_pager, - plain_pager, tempfile_pager, tty_pager) +from _pyrepl.pager import (get_pager, escape_less, pipe_pager, + plain_pager, tempfile_pager, tty_pager, + plain) # noqa # --------------------------------------------------------- old names diff --git a/Lib/site.py b/Lib/site.py index 7eace190f5ab21..045e2b79556847 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -485,10 +485,10 @@ def register_readline(): """ import atexit try: - import readline - import rlcompleter - import _pyrepl.readline - import _pyrepl.unix_console + import readline # noqa + import rlcompleter # noqa + import _pyrepl.readline # noqa + import _pyrepl.unix_console # noqa except ImportError: return @@ -603,7 +603,7 @@ def execsitecustomize(): """Run custom site specific code, if available.""" try: try: - import sitecustomize + import sitecustomize # noqa 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 except ImportError as exc: if exc.name == 'usercustomize': pass diff --git a/Lib/ssl.py b/Lib/ssl.py index cc685c2cc405ab..f430d2f95a1f4f 100644 --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -99,26 +99,26 @@ import _ssl # if we can't import it, let the error propagate -from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION -from _ssl import _SSLContext, MemoryBIO, SSLSession +from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION # noqa +from _ssl import _SSLContext, MemoryBIO, SSLSession # noqa from _ssl import ( - SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError, - SSLSyscallError, SSLEOFError, SSLCertVerificationError + SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError, # noqa + SSLSyscallError, SSLEOFError, SSLCertVerificationError # noqa ) from _ssl import txt2obj as _txt2obj, nid2obj as _nid2obj -from _ssl import RAND_status, RAND_add, RAND_bytes +from _ssl import RAND_status, RAND_add, RAND_bytes # noqa try: - from _ssl import RAND_egd + from _ssl import RAND_egd # noqa except ImportError: # RAND_egd is not supported on some platforms pass from _ssl import ( - HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1, - HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK + HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1, # noqa + HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK # noqa ) -from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION +from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION # noqa _IntEnum._convert_( '_SSLMethod', __name__, @@ -255,7 +255,7 @@ class _TLSMessageType: if sys.platform == "win32": - from _ssl import enum_certificates, enum_crls + from _ssl import enum_certificates, enum_crls # noqa from socket import socket, SOCK_STREAM, create_connection from socket import SOL_SOCKET, SO_TYPE, _GLOBAL_DEFAULT_TIMEOUT diff --git a/Lib/struct.py b/Lib/struct.py index d6bba588636498..b7d2f7b71eca16 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 +from _struct import __doc__ # noqa diff --git a/Lib/subprocess.py b/Lib/subprocess.py index b2dcb1454c139e..9b8a7bda331462 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -79,16 +79,16 @@ if _mswindows: import _winapi - from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP, - STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, - STD_ERROR_HANDLE, SW_HIDE, - STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW, - STARTF_FORCEONFEEDBACK, STARTF_FORCEOFFFEEDBACK, - ABOVE_NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, - HIGH_PRIORITY_CLASS, IDLE_PRIORITY_CLASS, - NORMAL_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS, - CREATE_NO_WINDOW, DETACHED_PROCESS, - CREATE_DEFAULT_ERROR_MODE, CREATE_BREAKAWAY_FROM_JOB) + from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP, # noqa + STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, # noqa + STD_ERROR_HANDLE, SW_HIDE, # noqa + STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW, # noqa + STARTF_FORCEONFEEDBACK, STARTF_FORCEOFFFEEDBACK, # noqa + ABOVE_NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, # noqa + HIGH_PRIORITY_CLASS, IDLE_PRIORITY_CLASS, # noqa + NORMAL_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS, # noqa + CREATE_NO_WINDOW, DETACHED_PROCESS, # noqa + CREATE_DEFAULT_ERROR_MODE, CREATE_BREAKAWAY_FROM_JOB) # noqa __all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP", "STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE", diff --git a/Lib/symtable.py b/Lib/symtable.py index d6ac1f527ba8ba..4e8eb4c2b32bf8 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_NONLOCAL, DEF_LOCAL, + DEF_PARAM, DEF_TYPE_PARAM, DEF_FREE_CLASS, + DEF_GLOBAL, # noqa DEF_IMPORT, DEF_BOUND, DEF_ANNOT, DEF_COMP_ITER, DEF_COMP_CELL, SCOPE_OFF, SCOPE_MASK, From 19ceb4d6dcde3857b7d535cd61c05c41250f38c8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 12 Jun 2024 18:41:34 +0200 Subject: [PATCH 2/8] Add more # noqa for more fun --- Lib/collections/__init__.py | 2 +- Lib/collections/abc.py | 4 ++-- Lib/ctypes/__init__.py | 28 ++++++++++++++-------------- Lib/curses/__init__.py | 4 ++-- Lib/importlib/machinery.py | 28 ++++++++++++++-------------- Lib/importlib/util.py | 14 +++++++------- Lib/multiprocessing/context.py | 2 +- Lib/re/_constants.py | 2 +- Lib/sqlite3/__main__.py | 2 +- Lib/urllib/request.py | 2 +- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index a17100e6c02a0e..882963b3302be9 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -46,7 +46,7 @@ _collections_abc.MutableSequence.register(deque) try: - from _collections import _deque_iterator + from _collections import _deque_iterator # noqa except ImportError: pass diff --git a/Lib/collections/abc.py b/Lib/collections/abc.py index 86ca8b8a8414b3..d3d0d3c66270c3 100644 --- a/Lib/collections/abc.py +++ b/Lib/collections/abc.py @@ -1,3 +1,3 @@ from _collections_abc import * -from _collections_abc import __all__ -from _collections_abc import _CallableGenericAlias +from _collections_abc import __all__ # noqa +from _collections_abc import _CallableGenericAlias # noqa diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index b7ee46d664ab08..b26f139d362724 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -5,13 +5,13 @@ __version__ = "1.1.0" -from _ctypes import Union, Structure, Array -from _ctypes import _Pointer -from _ctypes import CFuncPtr as _CFuncPtr -from _ctypes import __version__ as _ctypes_version -from _ctypes import RTLD_LOCAL, RTLD_GLOBAL -from _ctypes import ArgumentError -from _ctypes import SIZEOF_TIME_T +from _ctypes import Union, Structure, Array # noqa +from _ctypes import _Pointer # noqa +from _ctypes import CFuncPtr as _CFuncPtr # noqa +from _ctypes import __version__ as _ctypes_version # noqa +from _ctypes import RTLD_LOCAL, RTLD_GLOBAL # noqa +from _ctypes import ArgumentError # noqa +from _ctypes import SIZEOF_TIME_T # noqa from struct import calcsize as _calcsize @@ -138,9 +138,9 @@ class WinFunctionType(_CFuncPtr): elif _os.name == "posix": from _ctypes import dlopen as _dlopen -from _ctypes import sizeof, byref, addressof, alignment, resize -from _ctypes import get_errno, set_errno -from _ctypes import _SimpleCData +from _ctypes import sizeof, byref, addressof, alignment, resize # noqa +from _ctypes import get_errno, set_errno # noqa +from _ctypes import _SimpleCData # noqa def _check_size(typ, typecode=None): # Check if sizeof(ctypes_type) against struct.calcsize. This @@ -252,7 +252,7 @@ class c_void_p(_SimpleCData): class c_bool(_SimpleCData): _type_ = "?" -from _ctypes import POINTER, pointer, _pointer_type_cache +from _ctypes import POINTER, pointer, _pointer_type_cache # noqa class c_wchar_p(_SimpleCData): _type_ = "Z" @@ -492,7 +492,7 @@ def LoadLibrary(self, name): oledll = LibraryLoader(OleDLL) GetLastError = windll.kernel32.GetLastError - from _ctypes import get_last_error, set_last_error + from _ctypes import get_last_error, set_last_error # noqa def WinError(code=None, descr=None): if code is None: @@ -568,8 +568,8 @@ def DllCanUnloadNow(): return 0 # S_OK return ccom.DllCanUnloadNow() -from ctypes._endian import BigEndianStructure, LittleEndianStructure -from ctypes._endian import BigEndianUnion, LittleEndianUnion +from ctypes._endian import BigEndianStructure, LittleEndianStructure # noqa +from ctypes._endian import BigEndianUnion, LittleEndianUnion # noqa # Fill in specifically-sized types c_int8 = c_byte diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py index 69270bfcd2b205..7819f936014286 100644 --- a/Lib/curses/__init__.py +++ b/Lib/curses/__init__.py @@ -51,9 +51,9 @@ def start_color(): # Import Python has_key() implementation if _curses doesn't contain has_key() try: - has_key + has_key # noqa except NameError: - from .has_key import has_key + from .has_key import has_key # noqa # 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/importlib/machinery.py b/Lib/importlib/machinery.py index fbd30b159fb752..dd8f50b41f58f7 100644 --- a/Lib/importlib/machinery.py +++ b/Lib/importlib/machinery.py @@ -1,19 +1,19 @@ """The machinery of importlib: finders, loaders, hooks, etc.""" -from ._bootstrap import ModuleSpec -from ._bootstrap import BuiltinImporter -from ._bootstrap import FrozenImporter -from ._bootstrap_external import (SOURCE_SUFFIXES, DEBUG_BYTECODE_SUFFIXES, - OPTIMIZED_BYTECODE_SUFFIXES, BYTECODE_SUFFIXES, - EXTENSION_SUFFIXES) -from ._bootstrap_external import WindowsRegistryFinder -from ._bootstrap_external import PathFinder -from ._bootstrap_external import FileFinder -from ._bootstrap_external import SourceFileLoader -from ._bootstrap_external import SourcelessFileLoader -from ._bootstrap_external import ExtensionFileLoader -from ._bootstrap_external import AppleFrameworkLoader -from ._bootstrap_external import NamespaceLoader +from ._bootstrap import ModuleSpec # noqa +from ._bootstrap import BuiltinImporter # noqa +from ._bootstrap import FrozenImporter # noqa +from ._bootstrap_external import (SOURCE_SUFFIXES, DEBUG_BYTECODE_SUFFIXES, # noqa + OPTIMIZED_BYTECODE_SUFFIXES, BYTECODE_SUFFIXES, # noqa + EXTENSION_SUFFIXES) # noqa +from ._bootstrap_external import WindowsRegistryFinder # noqa +from ._bootstrap_external import PathFinder # noqa +from ._bootstrap_external import FileFinder # noqa +from ._bootstrap_external import SourceFileLoader # noqa +from ._bootstrap_external import SourcelessFileLoader # noqa +from ._bootstrap_external import ExtensionFileLoader # noqa +from ._bootstrap_external import AppleFrameworkLoader # noqa +from ._bootstrap_external import NamespaceLoader # noqa def all_suffixes(): diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py index c94a148e4c50e0..b87be6005bf12b 100644 --- a/Lib/importlib/util.py +++ b/Lib/importlib/util.py @@ -1,15 +1,15 @@ """Utility code for constructing importers, etc.""" from ._abc import Loader -from ._bootstrap import module_from_spec +from ._bootstrap import module_from_spec # noqa from ._bootstrap import _resolve_name -from ._bootstrap import spec_from_loader +from ._bootstrap import spec_from_loader # noqa from ._bootstrap import _find_spec -from ._bootstrap_external import MAGIC_NUMBER +from ._bootstrap_external import MAGIC_NUMBER # noqa from ._bootstrap_external import _RAW_MAGIC_NUMBER -from ._bootstrap_external import cache_from_source -from ._bootstrap_external import decode_source -from ._bootstrap_external import source_from_cache -from ._bootstrap_external import spec_from_file_location +from ._bootstrap_external import cache_from_source # noqa +from ._bootstrap_external import decode_source # noqa +from ._bootstrap_external import source_from_cache # noqa +from ._bootstrap_external import spec_from_file_location # noqa import _imp import sys diff --git a/Lib/multiprocessing/context.py b/Lib/multiprocessing/context.py index de8a264829dff3..734e8e0c0da564 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 def set_executable(self, executable): '''Sets the path to a python.exe or pythonw.exe binary used to run diff --git a/Lib/re/_constants.py b/Lib/re/_constants.py index 9c3c294ba448b4..f999056e4f3e25 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 # SRE standard exception (access as sre.error) # should this really be here? diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index b93b84384a0925..1f3c0bfe2af579 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 except ImportError: pass console.interact(banner, exitmsg="") diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index ac6719ce854182..a03a3a4ae31750 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -108,7 +108,7 @@ # check for SSL try: - import ssl + import ssl # noqa except ImportError: _have_ssl = False else: From 9b97f472931e2419ff6e375833af52fbb754a42f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 12 Jun 2024 18:50:33 +0200 Subject: [PATCH 3/8] One more #noqa batch --- Lib/concurrent/futures/process.py | 2 +- Lib/multiprocessing/util.py | 2 +- Lib/unittest/__init__.py | 4 ++-- Lib/xml/dom/__init__.py | 2 +- Lib/xml/sax/__init__.py | 10 +++++----- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py index bb4892ebdfedf5..ed25bc4ac2eef1 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 except ImportError: _system_limited = ( "This Python build lacks multiprocessing.synchronize, usually due " diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py index 75dde02d88c533..b83811393f91fc 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 from . import process diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py index f1f6c911ef17d9..182eea0fe4e0ba 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 from .loader import TestLoader, defaultTestLoader -from .main import TestProgram, main +from .main import TestProgram, main # noqa from .runner import TextTestRunner, TextTestResult from .signals import installHandler, registerResult, removeResult, removeHandler # IsolatedAsyncioTestCase will be imported lazily. diff --git a/Lib/xml/dom/__init__.py b/Lib/xml/dom/__init__.py index 97cf9a6429993d..27cd496f79545a 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 diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py index b657310207cfe5..fe1d99d83642f1 100644 --- a/Lib/xml/sax/__init__.py +++ b/Lib/xml/sax/__init__.py @@ -20,10 +20,10 @@ """ from .xmlreader import InputSource -from .handler import ContentHandler, ErrorHandler -from ._exceptions import SAXException, SAXNotRecognizedException, \ - SAXParseException, SAXNotSupportedException, \ - SAXReaderNotAvailable +from .handler import ContentHandler, ErrorHandler # noqa +from ._exceptions import (SAXException, SAXNotRecognizedException, # noqa + SAXParseException, SAXNotSupportedException, # noqa + SAXReaderNotAvailable) # noqa def parse(source, handler, errorHandler=ErrorHandler()): @@ -55,7 +55,7 @@ def parseString(string, handler, errorHandler=ErrorHandler()): # tell modulefinder that importing sax potentially imports expatreader _false = 0 if _false: - import xml.sax.expatreader + import xml.sax.expatreader # noqa import os, sys if not sys.flags.ignore_environment and "PY_SAX_PARSER" in os.environ: From 218966503321bbd8c053450a0c1756a8376392a4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 12 Jun 2024 19:05:25 +0200 Subject: [PATCH 4/8] Fix test_symtable --- Lib/symtable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/symtable.py b/Lib/symtable.py index 4e8eb4c2b32bf8..559698ce8c9ee7 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -3,9 +3,9 @@ import _symtable from _symtable import ( USE, + DEF_GLOBAL, # noqa DEF_NONLOCAL, DEF_LOCAL, DEF_PARAM, DEF_TYPE_PARAM, DEF_FREE_CLASS, - DEF_GLOBAL, # noqa DEF_IMPORT, DEF_BOUND, DEF_ANNOT, DEF_COMP_ITER, DEF_COMP_CELL, SCOPE_OFF, SCOPE_MASK, From e31a9e24f9c6a1d843c049be0ca0272e45194b5f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 12 Jun 2024 21:02:57 +0200 Subject: [PATCH 5/8] Revert --- Lib/collections/abc.py | 4 ++-- Lib/ctypes/__init__.py | 28 ++++++++++++++-------------- Lib/curses/__init__.py | 2 +- Lib/importlib/machinery.py | 28 ++++++++++++++-------------- Lib/importlib/util.py | 14 +++++++------- Lib/site.py | 12 ++++++------ Lib/ssl.py | 20 ++++++++++---------- Lib/subprocess.py | 20 ++++++++++---------- Lib/xml/sax/__init__.py | 10 +++++----- 9 files changed, 69 insertions(+), 69 deletions(-) diff --git a/Lib/collections/abc.py b/Lib/collections/abc.py index d3d0d3c66270c3..86ca8b8a8414b3 100644 --- a/Lib/collections/abc.py +++ b/Lib/collections/abc.py @@ -1,3 +1,3 @@ from _collections_abc import * -from _collections_abc import __all__ # noqa -from _collections_abc import _CallableGenericAlias # noqa +from _collections_abc import __all__ +from _collections_abc import _CallableGenericAlias diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index b26f139d362724..b7ee46d664ab08 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -5,13 +5,13 @@ __version__ = "1.1.0" -from _ctypes import Union, Structure, Array # noqa -from _ctypes import _Pointer # noqa -from _ctypes import CFuncPtr as _CFuncPtr # noqa -from _ctypes import __version__ as _ctypes_version # noqa -from _ctypes import RTLD_LOCAL, RTLD_GLOBAL # noqa -from _ctypes import ArgumentError # noqa -from _ctypes import SIZEOF_TIME_T # noqa +from _ctypes import Union, Structure, Array +from _ctypes import _Pointer +from _ctypes import CFuncPtr as _CFuncPtr +from _ctypes import __version__ as _ctypes_version +from _ctypes import RTLD_LOCAL, RTLD_GLOBAL +from _ctypes import ArgumentError +from _ctypes import SIZEOF_TIME_T from struct import calcsize as _calcsize @@ -138,9 +138,9 @@ class WinFunctionType(_CFuncPtr): elif _os.name == "posix": from _ctypes import dlopen as _dlopen -from _ctypes import sizeof, byref, addressof, alignment, resize # noqa -from _ctypes import get_errno, set_errno # noqa -from _ctypes import _SimpleCData # noqa +from _ctypes import sizeof, byref, addressof, alignment, resize +from _ctypes import get_errno, set_errno +from _ctypes import _SimpleCData def _check_size(typ, typecode=None): # Check if sizeof(ctypes_type) against struct.calcsize. This @@ -252,7 +252,7 @@ class c_void_p(_SimpleCData): class c_bool(_SimpleCData): _type_ = "?" -from _ctypes import POINTER, pointer, _pointer_type_cache # noqa +from _ctypes import POINTER, pointer, _pointer_type_cache class c_wchar_p(_SimpleCData): _type_ = "Z" @@ -492,7 +492,7 @@ def LoadLibrary(self, name): oledll = LibraryLoader(OleDLL) GetLastError = windll.kernel32.GetLastError - from _ctypes import get_last_error, set_last_error # noqa + from _ctypes import get_last_error, set_last_error def WinError(code=None, descr=None): if code is None: @@ -568,8 +568,8 @@ def DllCanUnloadNow(): return 0 # S_OK return ccom.DllCanUnloadNow() -from ctypes._endian import BigEndianStructure, LittleEndianStructure # noqa -from ctypes._endian import BigEndianUnion, LittleEndianUnion # noqa +from ctypes._endian import BigEndianStructure, LittleEndianStructure +from ctypes._endian import BigEndianUnion, LittleEndianUnion # Fill in specifically-sized types c_int8 = c_byte diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py index 7819f936014286..3566e18a785646 100644 --- a/Lib/curses/__init__.py +++ b/Lib/curses/__init__.py @@ -51,7 +51,7 @@ def start_color(): # Import Python has_key() implementation if _curses doesn't contain has_key() try: - has_key # noqa + has_key except NameError: from .has_key import has_key # noqa diff --git a/Lib/importlib/machinery.py b/Lib/importlib/machinery.py index dd8f50b41f58f7..fbd30b159fb752 100644 --- a/Lib/importlib/machinery.py +++ b/Lib/importlib/machinery.py @@ -1,19 +1,19 @@ """The machinery of importlib: finders, loaders, hooks, etc.""" -from ._bootstrap import ModuleSpec # noqa -from ._bootstrap import BuiltinImporter # noqa -from ._bootstrap import FrozenImporter # noqa -from ._bootstrap_external import (SOURCE_SUFFIXES, DEBUG_BYTECODE_SUFFIXES, # noqa - OPTIMIZED_BYTECODE_SUFFIXES, BYTECODE_SUFFIXES, # noqa - EXTENSION_SUFFIXES) # noqa -from ._bootstrap_external import WindowsRegistryFinder # noqa -from ._bootstrap_external import PathFinder # noqa -from ._bootstrap_external import FileFinder # noqa -from ._bootstrap_external import SourceFileLoader # noqa -from ._bootstrap_external import SourcelessFileLoader # noqa -from ._bootstrap_external import ExtensionFileLoader # noqa -from ._bootstrap_external import AppleFrameworkLoader # noqa -from ._bootstrap_external import NamespaceLoader # noqa +from ._bootstrap import ModuleSpec +from ._bootstrap import BuiltinImporter +from ._bootstrap import FrozenImporter +from ._bootstrap_external import (SOURCE_SUFFIXES, DEBUG_BYTECODE_SUFFIXES, + OPTIMIZED_BYTECODE_SUFFIXES, BYTECODE_SUFFIXES, + EXTENSION_SUFFIXES) +from ._bootstrap_external import WindowsRegistryFinder +from ._bootstrap_external import PathFinder +from ._bootstrap_external import FileFinder +from ._bootstrap_external import SourceFileLoader +from ._bootstrap_external import SourcelessFileLoader +from ._bootstrap_external import ExtensionFileLoader +from ._bootstrap_external import AppleFrameworkLoader +from ._bootstrap_external import NamespaceLoader def all_suffixes(): diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py index b87be6005bf12b..c94a148e4c50e0 100644 --- a/Lib/importlib/util.py +++ b/Lib/importlib/util.py @@ -1,15 +1,15 @@ """Utility code for constructing importers, etc.""" from ._abc import Loader -from ._bootstrap import module_from_spec # noqa +from ._bootstrap import module_from_spec from ._bootstrap import _resolve_name -from ._bootstrap import spec_from_loader # noqa +from ._bootstrap import spec_from_loader from ._bootstrap import _find_spec -from ._bootstrap_external import MAGIC_NUMBER # noqa +from ._bootstrap_external import MAGIC_NUMBER from ._bootstrap_external import _RAW_MAGIC_NUMBER -from ._bootstrap_external import cache_from_source # noqa -from ._bootstrap_external import decode_source # noqa -from ._bootstrap_external import source_from_cache # noqa -from ._bootstrap_external import spec_from_file_location # noqa +from ._bootstrap_external import cache_from_source +from ._bootstrap_external import decode_source +from ._bootstrap_external import source_from_cache +from ._bootstrap_external import spec_from_file_location import _imp import sys diff --git a/Lib/site.py b/Lib/site.py index 045e2b79556847..7eace190f5ab21 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -485,10 +485,10 @@ def register_readline(): """ import atexit try: - import readline # noqa - import rlcompleter # noqa - import _pyrepl.readline # noqa - import _pyrepl.unix_console # noqa + import readline + import rlcompleter + import _pyrepl.readline + import _pyrepl.unix_console except ImportError: return @@ -603,7 +603,7 @@ def execsitecustomize(): """Run custom site specific code, if available.""" try: try: - import sitecustomize # noqa + import sitecustomize 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 # noqa + import usercustomize except ImportError as exc: if exc.name == 'usercustomize': pass diff --git a/Lib/ssl.py b/Lib/ssl.py index f430d2f95a1f4f..cc685c2cc405ab 100644 --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -99,26 +99,26 @@ import _ssl # if we can't import it, let the error propagate -from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION # noqa -from _ssl import _SSLContext, MemoryBIO, SSLSession # noqa +from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION +from _ssl import _SSLContext, MemoryBIO, SSLSession from _ssl import ( - SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError, # noqa - SSLSyscallError, SSLEOFError, SSLCertVerificationError # noqa + SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError, + SSLSyscallError, SSLEOFError, SSLCertVerificationError ) from _ssl import txt2obj as _txt2obj, nid2obj as _nid2obj -from _ssl import RAND_status, RAND_add, RAND_bytes # noqa +from _ssl import RAND_status, RAND_add, RAND_bytes try: - from _ssl import RAND_egd # noqa + from _ssl import RAND_egd except ImportError: # RAND_egd is not supported on some platforms pass from _ssl import ( - HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1, # noqa - HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK # noqa + HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1, + HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK ) -from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION # noqa +from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION _IntEnum._convert_( '_SSLMethod', __name__, @@ -255,7 +255,7 @@ class _TLSMessageType: if sys.platform == "win32": - from _ssl import enum_certificates, enum_crls # noqa + from _ssl import enum_certificates, enum_crls from socket import socket, SOCK_STREAM, create_connection from socket import SOL_SOCKET, SO_TYPE, _GLOBAL_DEFAULT_TIMEOUT diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 9b8a7bda331462..b2dcb1454c139e 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -79,16 +79,16 @@ if _mswindows: import _winapi - from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP, # noqa - STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, # noqa - STD_ERROR_HANDLE, SW_HIDE, # noqa - STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW, # noqa - STARTF_FORCEONFEEDBACK, STARTF_FORCEOFFFEEDBACK, # noqa - ABOVE_NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, # noqa - HIGH_PRIORITY_CLASS, IDLE_PRIORITY_CLASS, # noqa - NORMAL_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS, # noqa - CREATE_NO_WINDOW, DETACHED_PROCESS, # noqa - CREATE_DEFAULT_ERROR_MODE, CREATE_BREAKAWAY_FROM_JOB) # noqa + from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP, + STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, + STD_ERROR_HANDLE, SW_HIDE, + STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW, + STARTF_FORCEONFEEDBACK, STARTF_FORCEOFFFEEDBACK, + ABOVE_NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, + HIGH_PRIORITY_CLASS, IDLE_PRIORITY_CLASS, + NORMAL_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS, + CREATE_NO_WINDOW, DETACHED_PROCESS, + CREATE_DEFAULT_ERROR_MODE, CREATE_BREAKAWAY_FROM_JOB) __all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP", "STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE", diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py index fe1d99d83642f1..b657310207cfe5 100644 --- a/Lib/xml/sax/__init__.py +++ b/Lib/xml/sax/__init__.py @@ -20,10 +20,10 @@ """ from .xmlreader import InputSource -from .handler import ContentHandler, ErrorHandler # noqa -from ._exceptions import (SAXException, SAXNotRecognizedException, # noqa - SAXParseException, SAXNotSupportedException, # noqa - SAXReaderNotAvailable) # noqa +from .handler import ContentHandler, ErrorHandler +from ._exceptions import SAXException, SAXNotRecognizedException, \ + SAXParseException, SAXNotSupportedException, \ + SAXReaderNotAvailable def parse(source, handler, errorHandler=ErrorHandler()): @@ -55,7 +55,7 @@ def parseString(string, handler, errorHandler=ErrorHandler()): # tell modulefinder that importing sax potentially imports expatreader _false = 0 if _false: - import xml.sax.expatreader # noqa + import xml.sax.expatreader import os, sys if not sys.flags.ignore_environment and "PY_SAX_PARSER" in os.environ: From 13efcc91cadd3519fb93d3d93968899e71e39cf0 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 12 Jun 2024 22:45:24 +0200 Subject: [PATCH 6/8] Add comments --- Lib/collections/__init__.py | 1 + Lib/pydoc.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 882963b3302be9..42a68c0d1a440f 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -46,6 +46,7 @@ _collections_abc.MutableSequence.register(deque) try: + # Expose _deque_iterator to support pickling deque iterators from _collections import _deque_iterator # noqa except ImportError: pass diff --git a/Lib/pydoc.py b/Lib/pydoc.py index fc344ea78f41f8..a54d4654b580e1 100644 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -77,7 +77,9 @@ class or function within a module or module in a package. If the from _pyrepl.pager import (get_pager, pipe_pager, plain_pager, tempfile_pager, tty_pager, - plain) # noqa + +# Expose plain() as pydoc.plain() +from _pyrepl.pager import plain # noqa # --------------------------------------------------------- old names From 648969cc4f89e00d2ca0855fb242e63623c51ab7 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 13 Jun 2024 11:39:07 +0300 Subject: [PATCH 7/8] Update Lib/pydoc.py --- Lib/pydoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index a54d4654b580e1..280cafcb43152a 100644 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -76,7 +76,7 @@ class or function within a module or module in a package. If the from traceback import format_exception_only from _pyrepl.pager import (get_pager, pipe_pager, - plain_pager, tempfile_pager, tty_pager, + plain_pager, tempfile_pager, tty_pager) # Expose plain() as pydoc.plain() from _pyrepl.pager import plain # noqa From 0506006524f926a0d3bacaa3c438822e4412ff82 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 13 Jun 2024 11:25:43 +0200 Subject: [PATCH 8/8] Use "# noqa: F401" --- Lib/_pyio.py | 2 +- Lib/code.py | 2 +- Lib/codecs.py | 2 +- Lib/collections/__init__.py | 2 +- Lib/concurrent/futures/process.py | 2 +- Lib/curses/__init__.py | 2 +- Lib/datetime.py | 4 ++-- Lib/decimal.py | 8 ++++---- Lib/hashlib.py | 2 +- Lib/lzma.py | 2 +- Lib/multiprocessing/context.py | 2 +- Lib/multiprocessing/util.py | 2 +- Lib/opcode.py | 4 ++-- Lib/operator.py | 2 +- Lib/platform.py | 2 +- Lib/pstats.py | 2 +- Lib/pydoc.py | 2 +- Lib/re/_constants.py | 2 +- Lib/site.py | 6 +++--- Lib/sqlite3/__main__.py | 2 +- Lib/struct.py | 4 ++-- Lib/symtable.py | 2 +- Lib/unittest/__init__.py | 4 ++-- Lib/urllib/request.py | 2 +- Lib/xml/dom/__init__.py | 2 +- 25 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 2abdace8dc950d..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) # noqa +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 ef3261128cda16..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 # noqa + import readline # noqa: F401 except ImportError: pass console.interact(banner, exitmsg) diff --git a/Lib/codecs.py b/Lib/codecs.py index 56d3379577181e..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 # noqa + import encodings # noqa: F401 diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 42a68c0d1a440f..b47e728484c8ac 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -47,7 +47,7 @@ try: # Expose _deque_iterator to support pickling deque iterators - from _collections import _deque_iterator # noqa + 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 ed25bc4ac2eef1..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 # noqa + 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 3566e18a785646..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 # noqa + 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 b9e8599f808268..b4f7bd045c7b68 100644 --- a/Lib/datetime.py +++ b/Lib/datetime.py @@ -1,9 +1,9 @@ try: from _datetime import * - from _datetime import __doc__ # noqa + from _datetime import __doc__ # noqa: F401 except ImportError: from _pydatetime import * - from _pydatetime import __doc__ # noqa + 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 70a890fd86b74f..13a0dcb77f1267 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -100,9 +100,9 @@ try: from _decimal import * - from _decimal import __version__ # noqa - from _decimal import __libmpdec_version__ # noqa + from _decimal import __version__ # noqa: F401 + from _decimal import __libmpdec_version__ # noqa: F401 except ImportError: from _pydecimal import * - from _pydecimal import __version__ # noqa - from _pydecimal import __libmpdec_version__ # noqa + from _pydecimal import __version__ # noqa: F401 + from _pydecimal import __libmpdec_version__ # noqa: F401 diff --git a/Lib/hashlib.py b/Lib/hashlib.py index 5c2fa55235f950..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 # noqa + from _hashlib import scrypt # noqa: F401 except ImportError: pass diff --git a/Lib/lzma.py b/Lib/lzma.py index 034805edeee919..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 # noqa +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 734e8e0c0da564..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 # noqa + 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 b83811393f91fc..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 # noqa +from subprocess import _args_from_interpreter_flags # noqa: F401 from . import process diff --git a/Lib/opcode.py b/Lib/opcode.py index 21ef4aca8bd4e3..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, # noqa - HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE) # noqa +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 1f685624763c2f..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__ # noqa + 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 ad1f147aebd47b..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 # noqa + import java.lang # noqa: F401 except ImportError: return release, vendor, vminfo, osinfo diff --git a/Lib/pstats.py b/Lib/pstats.py index 08c5321ee4ac2f..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 # noqa + import readline # noqa: F401 except ImportError: pass diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 280cafcb43152a..be5cd9a80db710 100644 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -79,7 +79,7 @@ class or function within a module or module in a package. If the plain_pager, tempfile_pager, tty_pager) # Expose plain() as pydoc.plain() -from _pyrepl.pager import plain # noqa +from _pyrepl.pager import plain # noqa: F401 # --------------------------------------------------------- old names diff --git a/Lib/re/_constants.py b/Lib/re/_constants.py index f999056e4f3e25..4cb88c96d92715 100644 --- a/Lib/re/_constants.py +++ b/Lib/re/_constants.py @@ -15,7 +15,7 @@ MAGIC = 20230612 -from _sre import MAXREPEAT, MAXGROUPS # noqa +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 1f3c0bfe2af579..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 # noqa + import readline # noqa: F401 except ImportError: pass console.interact(banner, exitmsg="") diff --git a/Lib/struct.py b/Lib/struct.py index b7d2f7b71eca16..ff98e8c4cb3f1d 100644 --- a/Lib/struct.py +++ b/Lib/struct.py @@ -11,5 +11,5 @@ ] from _struct import * -from _struct import _clearcache # noqa -from _struct import __doc__ # noqa +from _struct import _clearcache # noqa: F401 +from _struct import __doc__ # noqa: F401 diff --git a/Lib/symtable.py b/Lib/symtable.py index 559698ce8c9ee7..f8ba3496439535 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -3,7 +3,7 @@ import _symtable from _symtable import ( USE, - DEF_GLOBAL, # noqa + DEF_GLOBAL, # noqa: F401 DEF_NONLOCAL, DEF_LOCAL, DEF_PARAM, DEF_TYPE_PARAM, DEF_FREE_CLASS, DEF_IMPORT, DEF_BOUND, DEF_ANNOT, diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py index 182eea0fe4e0ba..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 # noqa +from .suite import BaseTestSuite, TestSuite # noqa: F401 from .loader import TestLoader, defaultTestLoader -from .main import TestProgram, main # noqa +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 a03a3a4ae31750..58b0cb574a764a 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -108,7 +108,7 @@ # check for SSL try: - import ssl # noqa + 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 27cd496f79545a..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 # noqa +from .domreg import getDOMImplementation, registerDOMImplementation # noqa: F401