Skip to content

Commit f6d03d4

Browse files
committed
pythongh-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 prevents the temptation to remove an import which is used effectively.
1 parent 97b69db commit f6d03d4

17 files changed

+46
-46
lines changed

Lib/_pyio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
_setmode = None
1717

1818
import io
19-
from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END)
19+
from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END) # noqa
2020

2121
valid_seek_flags = {0, 1, 2} # Hardwired values
2222
if hasattr(os, 'SEEK_HOLE') :

Lib/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def interact(banner=None, readfunc=None, local=None, exitmsg=None, local_exit=Fa
355355
console.raw_input = readfunc
356356
else:
357357
try:
358-
import readline
358+
import readline # noqa
359359
except ImportError:
360360
pass
361361
console.interact(banner, exitmsg)

Lib/codecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,4 +1129,4 @@ def make_encoding_map(decoding_map):
11291129
# package
11301130
_false = 0
11311131
if _false:
1132-
import encodings
1132+
import encodings # noqa

Lib/datetime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
try:
22
from _datetime import *
3-
from _datetime import __doc__
3+
from _datetime import __doc__ # noqa
44
except ImportError:
55
from _pydatetime import *
6-
from _pydatetime import __doc__
6+
from _pydatetime import __doc__ # noqa
77

88
__all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo",
99
"MINYEAR", "MAXYEAR", "UTC")

Lib/decimal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@
100100

101101
try:
102102
from _decimal import *
103-
from _decimal import __version__
104-
from _decimal import __libmpdec_version__
103+
from _decimal import __version__ # noqa
104+
from _decimal import __libmpdec_version__ # noqa
105105
except ImportError:
106106
from _pydecimal import *
107-
from _pydecimal import __version__
108-
from _pydecimal import __libmpdec_version__
107+
from _pydecimal import __version__ # noqa
108+
from _pydecimal import __libmpdec_version__ # noqa

Lib/hashlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def __hash_new(name, data=b'', **kwargs):
187187

188188
try:
189189
# OpenSSL's scrypt requires OpenSSL 1.1+
190-
from _hashlib import scrypt
190+
from _hashlib import scrypt # noqa
191191
except ImportError:
192192
pass
193193

Lib/lzma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import io
2626
import os
2727
from _lzma import *
28-
from _lzma import _encode_filter_properties, _decode_filter_properties
28+
from _lzma import _encode_filter_properties, _decode_filter_properties # noqa
2929
import _compression
3030

3131

Lib/opcode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import _opcode
1313
from _opcode import stack_effect
1414

15-
from _opcode_metadata import (_specializations, _specialized_opmap, opmap,
16-
HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE)
15+
from _opcode_metadata import (_specializations, _specialized_opmap, opmap, # noqa
16+
HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE) # noqa
1717
EXTENDED_ARG = opmap['EXTENDED_ARG']
1818

1919
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]

Lib/operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def ixor(a, b):
415415
except ImportError:
416416
pass
417417
else:
418-
from _operator import __doc__
418+
from _operator import __doc__ # noqa
419419

420420
# All of these "__func__ = func" assignments have to happen after importing
421421
# from _operator to make sure they're set to the right function

Lib/platform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', '')):
546546
warnings._deprecated('java_ver', remove=(3, 15))
547547
# Import the needed APIs
548548
try:
549-
import java.lang
549+
import java.lang # noqa
550550
except ImportError:
551551
return release, vendor, vminfo, osinfo
552552

Lib/pstats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def f8(x):
611611
if __name__ == '__main__':
612612
import cmd
613613
try:
614-
import readline
614+
import readline # noqa
615615
except ImportError:
616616
pass
617617

Lib/pydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class or function within a module or module in a package. If the
7575
from reprlib import Repr
7676
from traceback import format_exception_only
7777

78-
from _pyrepl.pager import (get_pager, plain, escape_less, pipe_pager,
78+
from _pyrepl.pager import (get_pager, escape_less, pipe_pager, # noqa
7979
plain_pager, tempfile_pager, tty_pager)
8080

8181

Lib/site.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ def register_readline():
485485
"""
486486
import atexit
487487
try:
488-
import readline
489-
import rlcompleter
490-
import _pyrepl.readline
491-
import _pyrepl.unix_console
488+
import readline # noqa
489+
import rlcompleter # noqa
490+
import _pyrepl.readline # noqa
491+
import _pyrepl.unix_console # noqa
492492
except ImportError:
493493
return
494494

@@ -603,7 +603,7 @@ def execsitecustomize():
603603
"""Run custom site specific code, if available."""
604604
try:
605605
try:
606-
import sitecustomize
606+
import sitecustomize # noqa
607607
except ImportError as exc:
608608
if exc.name == 'sitecustomize':
609609
pass
@@ -623,7 +623,7 @@ def execusercustomize():
623623
"""Run custom user specific code, if available."""
624624
try:
625625
try:
626-
import usercustomize
626+
import usercustomize # noqa
627627
except ImportError as exc:
628628
if exc.name == 'usercustomize':
629629
pass

Lib/ssl.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,26 @@
9999

100100
import _ssl # if we can't import it, let the error propagate
101101

102-
from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION
103-
from _ssl import _SSLContext, MemoryBIO, SSLSession
102+
from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION # noqa
103+
from _ssl import _SSLContext, MemoryBIO, SSLSession # noqa
104104
from _ssl import (
105-
SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError,
106-
SSLSyscallError, SSLEOFError, SSLCertVerificationError
105+
SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError, # noqa
106+
SSLSyscallError, SSLEOFError, SSLCertVerificationError # noqa
107107
)
108108
from _ssl import txt2obj as _txt2obj, nid2obj as _nid2obj
109-
from _ssl import RAND_status, RAND_add, RAND_bytes
109+
from _ssl import RAND_status, RAND_add, RAND_bytes # noqa
110110
try:
111-
from _ssl import RAND_egd
111+
from _ssl import RAND_egd # noqa
112112
except ImportError:
113113
# RAND_egd is not supported on some platforms
114114
pass
115115

116116

117117
from _ssl import (
118-
HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1,
119-
HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK
118+
HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1, # noqa
119+
HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK # noqa
120120
)
121-
from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION
121+
from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION # noqa
122122

123123
_IntEnum._convert_(
124124
'_SSLMethod', __name__,
@@ -255,7 +255,7 @@ class _TLSMessageType:
255255

256256

257257
if sys.platform == "win32":
258-
from _ssl import enum_certificates, enum_crls
258+
from _ssl import enum_certificates, enum_crls # noqa
259259

260260
from socket import socket, SOCK_STREAM, create_connection
261261
from socket import SOL_SOCKET, SO_TYPE, _GLOBAL_DEFAULT_TIMEOUT

Lib/struct.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
]
1212

1313
from _struct import *
14-
from _struct import _clearcache
15-
from _struct import __doc__
14+
from _struct import _clearcache # noqa
15+
from _struct import __doc__ # noqa

Lib/subprocess.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@
7979

8080
if _mswindows:
8181
import _winapi
82-
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
83-
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
84-
STD_ERROR_HANDLE, SW_HIDE,
85-
STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW,
86-
STARTF_FORCEONFEEDBACK, STARTF_FORCEOFFFEEDBACK,
87-
ABOVE_NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS,
88-
HIGH_PRIORITY_CLASS, IDLE_PRIORITY_CLASS,
89-
NORMAL_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS,
90-
CREATE_NO_WINDOW, DETACHED_PROCESS,
91-
CREATE_DEFAULT_ERROR_MODE, CREATE_BREAKAWAY_FROM_JOB)
82+
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP, # noqa
83+
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, # noqa
84+
STD_ERROR_HANDLE, SW_HIDE, # noqa
85+
STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW, # noqa
86+
STARTF_FORCEONFEEDBACK, STARTF_FORCEOFFFEEDBACK, # noqa
87+
ABOVE_NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, # noqa
88+
HIGH_PRIORITY_CLASS, IDLE_PRIORITY_CLASS, # noqa
89+
NORMAL_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS, # noqa
90+
CREATE_NO_WINDOW, DETACHED_PROCESS, # noqa
91+
CREATE_DEFAULT_ERROR_MODE, CREATE_BREAKAWAY_FROM_JOB) # noqa
9292

9393
__all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP",
9494
"STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE",

Lib/symtable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import _symtable
44
from _symtable import (
55
USE,
6-
DEF_GLOBAL, DEF_NONLOCAL, DEF_LOCAL,
6+
DEF_GLOBAL, DEF_NONLOCAL, DEF_LOCAL, # noqa
77
DEF_PARAM, DEF_TYPE_PARAM,
88
DEF_FREE_CLASS,
99
DEF_IMPORT, DEF_BOUND, DEF_ANNOT,

0 commit comments

Comments
 (0)