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

Function fix_missing_locations

tools/python-3.11.9-amd64/Lib/ast.py:197–229  ·  view source on GitHub ↗

When you compile a node tree with compile(), the compiler expects lineno and col_offset attributes for every node that supports them. This is rather tedious to fill in for generated nodes, so this helper adds these attributes recursively where not already set, by setting them t

(node)

Source from the content-addressed store, hash-verified

195
196
197def fix_missing_locations(node):
198 """
199 When you compile a node tree with compile(), the compiler expects lineno and
200 col_offset attributes for every node that supports them. This is rather
201 tedious to fill in for generated nodes, so this helper adds these attributes
202 recursively where not already set, by setting them to the values of the
203 parent node. It works recursively starting at *node*.
204 """
205 def _fix(node, lineno, col_offset, end_lineno, end_col_offset):
206 if 'lineno' in node._attributes:
207 if not hasattr(node, 'lineno'):
208 node.lineno = lineno
209 else:
210 lineno = node.lineno
211 if 'end_lineno' in node._attributes:
212 if getattr(node, 'end_lineno', None) is None:
213 node.end_lineno = end_lineno
214 else:
215 end_lineno = node.end_lineno
216 if 'col_offset' in node._attributes:
217 if not hasattr(node, 'col_offset'):
218 node.col_offset = col_offset
219 else:
220 col_offset = node.col_offset
221 if 'end_col_offset' in node._attributes:
222 if getattr(node, 'end_col_offset', None) is None:
223 node.end_col_offset = end_col_offset
224 else:
225 end_col_offset = node.end_col_offset
226 for child in iter_child_nodes(node):
227 _fix(child, lineno, col_offset, end_lineno, end_col_offset)
228 _fix(node, 1, 0, 1, 0)
229 return node
230
231
232def increment_lineno(node, n=1):

Callers

nothing calls this directly

Calls 1

_fixFunction · 0.85

Tested by

no test coverage detected