diff options
author | Georg Brandl <georg@python.org> | 2011-01-09 07:38:51 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2011-01-09 07:38:51 +0000 |
commit | 619e7ba8148cb9ebf11a1331c788b6713e88ca5d (patch) | |
tree | 160522c207fc7f9ee88f239c03e7ccf87365fcec /Lib/ast.py | |
parent | 5b2d9ddf69cecfb9ad4e687fab3f34ecc5a9ea4f (diff) | |
download | cpython-git-619e7ba8148cb9ebf11a1331c788b6713e88ca5d.tar.gz |
#10869: do not visit root node twice in ast.increment_lineno().
Diffstat (limited to 'Lib/ast.py')
-rw-r--r-- | Lib/ast.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Lib/ast.py b/Lib/ast.py index 4b2063bd78..ba880c93ec 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -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]) |