Skip to content

Commit 6ae254a

Browse files
authored
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.
1 parent ca5108a commit 6ae254a

25 files changed

+40
-36
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: F401
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: F401
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: F401

Lib/collections/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
_collections_abc.MutableSequence.register(deque)
4747

4848
try:
49-
from _collections import _deque_iterator
49+
# Expose _deque_iterator to support pickling deque iterators
50+
from _collections import _deque_iterator # noqa: F401
5051
except ImportError:
5152
pass
5253

Lib/concurrent/futures/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def _check_system_limits():
589589
raise NotImplementedError(_system_limited)
590590
_system_limits_checked = True
591591
try:
592-
import multiprocessing.synchronize
592+
import multiprocessing.synchronize # noqa: F401
593593
except ImportError:
594594
_system_limited = (
595595
"This Python build lacks multiprocessing.synchronize, usually due "

Lib/curses/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def start_color():
5353
try:
5454
has_key
5555
except NameError:
56-
from .has_key import has_key
56+
from .has_key import has_key # noqa: F401
5757

5858
# Wrapper for the entire curses-based application. Runs a function which
5959
# should be the rest of your curses-based application. If the application

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: F401
44
except ImportError:
55
from _pydatetime import *
6-
from _pydatetime import __doc__
6+
from _pydatetime import __doc__ # noqa: F401
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: F401
104+
from _decimal import __libmpdec_version__ # noqa: F401
105105
except ImportError:
106106
from _pydecimal import *
107-
from _pydecimal import __version__
108-
from _pydecimal import __libmpdec_version__
107+
from _pydecimal import __version__ # noqa: F401
108+
from _pydecimal import __libmpdec_version__ # noqa: F401

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: F401
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: F401
2929
import _compression
3030

3131

Lib/multiprocessing/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def allow_connection_pickling(self):
167167
'''
168168
# This is undocumented. In previous versions of multiprocessing
169169
# its only effect was to make socket objects inheritable on Windows.
170-
from . import connection
170+
from . import connection # noqa: F401
171171

172172
def set_executable(self, executable):
173173
'''Sets the path to a python.exe or pythonw.exe binary used to run

Lib/multiprocessing/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import atexit
1515
import threading # we want threading to install it's
1616
# cleanup function before multiprocessing does
17-
from subprocess import _args_from_interpreter_flags
17+
from subprocess import _args_from_interpreter_flags # noqa: F401
1818

1919
from . import process
2020

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: F401
16+
HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE) # noqa: F401
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: F401
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: F401
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: F401
615615
except ImportError:
616616
pass
617617

Lib/pydoc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ 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, pipe_pager,
78+
from _pyrepl.pager import (get_pager, pipe_pager,
7979
plain_pager, tempfile_pager, tty_pager)
8080

81+
# Expose plain() as pydoc.plain()
82+
from _pyrepl.pager import plain # noqa: F401
83+
8184

8285
# --------------------------------------------------------- old names
8386

Lib/re/_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
MAGIC = 20230612
1717

18-
from _sre import MAXREPEAT, MAXGROUPS
18+
from _sre import MAXREPEAT, MAXGROUPS # noqa: F401
1919

2020
# SRE standard exception (access as sre.error)
2121
# should this really be here?

Lib/site.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def register_readline():
486486
import atexit
487487
try:
488488
import readline
489-
import rlcompleter
489+
import rlcompleter # noqa: F401
490490
import _pyrepl.readline
491491
import _pyrepl.unix_console
492492
except ImportError:
@@ -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: F401
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: F401
627627
except ImportError as exc:
628628
if exc.name == 'usercustomize':
629629
pass

Lib/sqlite3/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def main(*args):
117117
# No SQL provided; start the REPL.
118118
console = SqliteInteractiveConsole(con)
119119
try:
120-
import readline
120+
import readline # noqa: F401
121121
except ImportError:
122122
pass
123123
console.interact(banner, exitmsg="")

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: F401
15+
from _struct import __doc__ # noqa: F401

Lib/symtable.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import _symtable
44
from _symtable import (
55
USE,
6-
DEF_GLOBAL, DEF_NONLOCAL, DEF_LOCAL,
7-
DEF_PARAM, DEF_TYPE_PARAM,
8-
DEF_FREE_CLASS,
6+
DEF_GLOBAL, # noqa: F401
7+
DEF_NONLOCAL, DEF_LOCAL,
8+
DEF_PARAM, DEF_TYPE_PARAM, DEF_FREE_CLASS,
99
DEF_IMPORT, DEF_BOUND, DEF_ANNOT,
1010
DEF_COMP_ITER, DEF_COMP_CELL,
1111
SCOPE_OFF, SCOPE_MASK,

Lib/unittest/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def testMultiply(self):
5757
from .case import (addModuleCleanup, TestCase, FunctionTestCase, SkipTest, skip,
5858
skipIf, skipUnless, expectedFailure, doModuleCleanups,
5959
enterModuleContext)
60-
from .suite import BaseTestSuite, TestSuite
60+
from .suite import BaseTestSuite, TestSuite # noqa: F401
6161
from .loader import TestLoader, defaultTestLoader
62-
from .main import TestProgram, main
62+
from .main import TestProgram, main # noqa: F401
6363
from .runner import TextTestRunner, TextTestResult
6464
from .signals import installHandler, registerResult, removeResult, removeHandler
6565
# IsolatedAsyncioTestCase will be imported lazily.

Lib/urllib/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

109109
# check for SSL
110110
try:
111-
import ssl
111+
import ssl # noqa: F401
112112
except ImportError:
113113
_have_ssl = False
114114
else:

Lib/xml/dom/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ class UserDataHandler:
137137
EMPTY_NAMESPACE = None
138138
EMPTY_PREFIX = None
139139

140-
from .domreg import getDOMImplementation, registerDOMImplementation
140+
from .domreg import getDOMImplementation, registerDOMImplementation # noqa: F401

0 commit comments

Comments
 (0)