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

Function increment_lineno

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

Increment the line number and end line number of each node in the tree starting at *node* by *n*. This is useful to "move code" to a different location in a file.

(node, n=1)

Source from the content-addressed store, hash-verified

230
231
232def increment_lineno(node, n=1):
233 """
234 Increment the line number and end line number of each node in the tree
235 starting at *node* by *n*. This is useful to "move code" to a different
236 location in a file.
237 """
238 for child in walk(node):
239 # TypeIgnore is a special case where lineno is not an attribute
240 # but rather a field of the node itself.
241 if isinstance(child, TypeIgnore):
242 child.lineno = getattr(child, 'lineno', 0) + n
243 continue
244
245 if 'lineno' in child._attributes:
246 child.lineno = getattr(child, 'lineno', 0) + n
247 if (
248 "end_lineno" in child._attributes
249 and (end_lineno := getattr(child, "end_lineno", 0)) is not None
250 ):
251 child.end_lineno = end_lineno + n
252 return node
253
254
255def iter_fields(node):

Callers

nothing calls this directly

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected