MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / FutureFinder

Class FutureFinder

tools/python-3.11.9-amd64/Tools/scripts/cleanfuture.py:133–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131 print("unchanged.")
132
133class FutureFinder:
134
135 def __init__(self, f, fname):
136 self.f = f
137 self.fname = fname
138 self.ateof = 0
139 self.lines = [] # raw file lines
140
141 # List of (start_index, end_index, new_line) triples.
142 self.changed = []
143
144 # Line-getter for tokenize.
145 def getline(self):
146 if self.ateof:
147 return ""
148 line = self.f.readline()
149 if line == "":
150 self.ateof = 1
151 else:
152 self.lines.append(line)
153 return line
154
155 def run(self):
156 STRING = tokenize.STRING
157 NL = tokenize.NL
158 NEWLINE = tokenize.NEWLINE
159 COMMENT = tokenize.COMMENT
160 NAME = tokenize.NAME
161 OP = tokenize.OP
162
163 changed = self.changed
164 get = tokenize.generate_tokens(self.getline).__next__
165 type, token, (srow, scol), (erow, ecol), line = get()
166
167 # Chew up initial comments and blank lines (if any).
168 while type in (COMMENT, NL, NEWLINE):
169 type, token, (srow, scol), (erow, ecol), line = get()
170
171 # Chew up docstring (if any -- and it may be implicitly catenated!).
172 while type is STRING:
173 type, token, (srow, scol), (erow, ecol), line = get()
174
175 # Analyze the future stmts.
176 while 1:
177 # Chew up comments and blank lines (if any).
178 while type in (COMMENT, NL, NEWLINE):
179 type, token, (srow, scol), (erow, ecol), line = get()
180
181 if not (type is NAME and token == "from"):
182 break
183 startline = srow - 1 # tokenize is one-based
184 type, token, (srow, scol), (erow, ecol), line = get()
185
186 if not (type is NAME and token == "__future__"):
187 break
188 type, token, (srow, scol), (erow, ecol), line = get()
189
190 if not (type is NAME and token == "import"):

Callers 1

checkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected