Skip to content

Commit fdacefb

Browse files
committed
Use PEP810!
1 parent 408e1ad commit fdacefb

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Lib/inspect.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@
163163
from collections import namedtuple, OrderedDict
164164
from _weakref import ref as make_weakref
165165

166+
lazy import re
167+
lazy import tokenize
168+
166169
# Create constants for the compiler flags in Include/code.h
167170
# We try to get them from dis to avoid duplication
168171
mod_dict = globals()
@@ -1087,8 +1090,6 @@ def __init__(self):
10871090
self.body_col0 = None
10881091

10891092
def tokeneater(self, type, token, srowcol, erowcol, line):
1090-
import tokenize
1091-
10921093
if not self.started and not self.indecorator:
10931094
if type in (tokenize.INDENT, tokenize.COMMENT, tokenize.NL):
10941095
pass
@@ -1139,8 +1140,6 @@ def tokeneater(self, type, token, srowcol, erowcol, line):
11391140
def getblock(lines):
11401141
"""Extract the block of code at the top of the given list of lines."""
11411142
blockfinder = BlockFinder()
1142-
import tokenize
1143-
11441143
try:
11451144
tokens = tokenize.generate_tokens(iter(lines).__next__)
11461145
for _token in tokens:
@@ -1369,7 +1368,6 @@ def formatannotation(annotation, base_module=None, *, quote_annotation_strings=T
13691368
def repl(match):
13701369
text = match.group()
13711370
return text.removeprefix('typing.')
1372-
import re
13731371
return re.sub(r'[\w\.]+', repl, repr(annotation))
13741372
if isinstance(annotation, types.GenericAlias):
13751373
return str(annotation)
@@ -2120,7 +2118,6 @@ def _signature_strip_non_python_syntax(signature):
21202118
lines = [l.encode('ascii') for l in signature.split('\n') if l]
21212119
generator = iter(lines).__next__
21222120

2123-
import tokenize
21242121
token_stream = tokenize.tokenize(generator)
21252122

21262123
text = []

0 commit comments

Comments
 (0)