mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +00:00
#10869: do not visit root node twice in ast.increment_lineno().
This commit is contained in:
parent
5b2d9ddf69
commit
619e7ba814
5 changed files with 17 additions and 8 deletions
|
@ -159,8 +159,6 @@ def increment_lineno(node, n=1):
|
|||
Increment the 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.
|
||||
"""
|
||||
if 'lineno' in node._attributes:
|
||||
node.lineno = getattr(node, 'lineno', 0) + n
|
||||
for child in walk(node):
|
||||
if 'lineno' in child._attributes:
|
||||
child.lineno = getattr(child, 'lineno', 0) + n
|
||||
|
@ -211,9 +209,9 @@ def get_docstring(node, clean=True):
|
|||
|
||||
def walk(node):
|
||||
"""
|
||||
Recursively yield all child nodes of *node*, in no specified order. This is
|
||||
useful if you only want to modify nodes in place and don't care about the
|
||||
context.
|
||||
Recursively yield all descendant nodes in the tree starting at *node*
|
||||
(including *node* itself), in no specified order. This is useful if you
|
||||
only want to modify nodes in place and don't care about the context.
|
||||
"""
|
||||
from collections import deque
|
||||
todo = deque([node])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue