MCPcopy Index your code
hub / github.com/python/cpython / increment_lineno

Function increment_lineno

Lib/ast.py:259–279  ·  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

257
258
259def increment_lineno(node, n=1):
260 """
261 Increment the line number and end line number of each node in the tree
262 starting at *node* by *n*. This is useful to "move code" to a different
263 location in a file.
264 """
265 for child in walk(node):
266 # TypeIgnore is a special case where lineno is not an attribute
267 # but rather a field of the node itself.
268 if isinstance(child, TypeIgnore):
269 child.lineno = getattr(child, 'lineno', 0) + n
270 continue
271
272 if 'lineno' in child._attributes:
273 child.lineno = getattr(child, 'lineno', 0) + n
274 if (
275 "end_lineno" in child._attributes
276 and (end_lineno := getattr(child, "end_lineno", 0)) is not None
277 ):
278 child.end_lineno = end_lineno + n
279 return node
280
281
282def iter_fields(node):

Callers

nothing calls this directly

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…