|
163 | 163 | from collections import namedtuple, OrderedDict |
164 | 164 | from _weakref import ref as make_weakref |
165 | 165 |
|
| 166 | +lazy import re |
| 167 | +lazy import tokenize |
| 168 | + |
166 | 169 | # Create constants for the compiler flags in Include/code.h |
167 | 170 | # We try to get them from dis to avoid duplication |
168 | 171 | mod_dict = globals() |
@@ -1087,8 +1090,6 @@ def __init__(self): |
1087 | 1090 | self.body_col0 = None |
1088 | 1091 |
|
1089 | 1092 | def tokeneater(self, type, token, srowcol, erowcol, line): |
1090 | | - import tokenize |
1091 | | - |
1092 | 1093 | if not self.started and not self.indecorator: |
1093 | 1094 | if type in (tokenize.INDENT, tokenize.COMMENT, tokenize.NL): |
1094 | 1095 | pass |
@@ -1139,8 +1140,6 @@ def tokeneater(self, type, token, srowcol, erowcol, line): |
1139 | 1140 | def getblock(lines): |
1140 | 1141 | """Extract the block of code at the top of the given list of lines.""" |
1141 | 1142 | blockfinder = BlockFinder() |
1142 | | - import tokenize |
1143 | | - |
1144 | 1143 | try: |
1145 | 1144 | tokens = tokenize.generate_tokens(iter(lines).__next__) |
1146 | 1145 | for _token in tokens: |
@@ -1369,7 +1368,6 @@ def formatannotation(annotation, base_module=None, *, quote_annotation_strings=T |
1369 | 1368 | def repl(match): |
1370 | 1369 | text = match.group() |
1371 | 1370 | return text.removeprefix('typing.') |
1372 | | - import re |
1373 | 1371 | return re.sub(r'[\w\.]+', repl, repr(annotation)) |
1374 | 1372 | if isinstance(annotation, types.GenericAlias): |
1375 | 1373 | return str(annotation) |
@@ -2120,7 +2118,6 @@ def _signature_strip_non_python_syntax(signature): |
2120 | 2118 | lines = [l.encode('ascii') for l in signature.split('\n') if l] |
2121 | 2119 | generator = iter(lines).__next__ |
2122 | 2120 |
|
2123 | | - import tokenize |
2124 | 2121 | token_stream = tokenize.tokenize(generator) |
2125 | 2122 |
|
2126 | 2123 | text = [] |
|
0 commit comments