[Python-checkins] r87881 - in python/branches/release31-maint: Doc/library/ast.rst Lib/ast.py Lib/test/test_ast.py Misc/ACKS Misc/NEWS

georg.brandl python-checkins at python.org
Sun Jan 9 08:55:46 CET 2011


Author: georg.brandl
Date: Sun Jan  9 08:55:46 2011
New Revision: 87881

Log:
Merged revisions 87876-87877 via svnmerge from 
svn+ssh://svn.python.org/python/branches/py3k

........
  r87876 | georg.brandl | 2011-01-09 08:38:51 +0100 (So, 09 Jan 2011) | 1 line
  
  #10869: do not visit root node twice in ast.increment_lineno().
........
  r87877 | georg.brandl | 2011-01-09 08:50:48 +0100 (So, 09 Jan 2011) | 1 line
  
  Add missing line.
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Doc/library/ast.rst
   python/branches/release31-maint/Lib/ast.py
   python/branches/release31-maint/Lib/test/test_ast.py
   python/branches/release31-maint/Misc/ACKS
   python/branches/release31-maint/Misc/NEWS

Modified: python/branches/release31-maint/Doc/library/ast.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/ast.rst	(original)
+++ python/branches/release31-maint/Doc/library/ast.rst	Sun Jan  9 08:55:46 2011
@@ -167,9 +167,9 @@
 
 .. function:: 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.
 
 
 .. class:: NodeVisitor()

Modified: python/branches/release31-maint/Lib/ast.py
==============================================================================
--- python/branches/release31-maint/Lib/ast.py	(original)
+++ python/branches/release31-maint/Lib/ast.py	Sun Jan  9 08:55:46 2011
@@ -152,8 +152,6 @@
     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
@@ -204,9 +202,9 @@
 
 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])

Modified: python/branches/release31-maint/Lib/test/test_ast.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_ast.py	(original)
+++ python/branches/release31-maint/Lib/test/test_ast.py	Sun Jan  9 08:55:46 2011
@@ -253,6 +253,14 @@
             'op=Add(), right=Num(n=1, lineno=4, col_offset=4), lineno=4, '
             'col_offset=0))'
         )
+        # issue10869: do not increment lineno of root twice
+        src = ast.parse('1 + 1', mode='eval')
+        self.assertEqual(ast.increment_lineno(src.body, n=3), src.body)
+        self.assertEqual(ast.dump(src, include_attributes=True),
+            'Expression(body=BinOp(left=Num(n=1, lineno=4, col_offset=0), '
+            'op=Add(), right=Num(n=1, lineno=4, col_offset=4), lineno=4, '
+            'col_offset=0))'
+        )
 
     def test_iter_fields(self):
         node = ast.parse('foo()', mode='eval')

Modified: python/branches/release31-maint/Misc/ACKS
==============================================================================
--- python/branches/release31-maint/Misc/ACKS	(original)
+++ python/branches/release31-maint/Misc/ACKS	Sun Jan  9 08:55:46 2011
@@ -841,6 +841,7 @@
 Rickard Westman
 Jeff Wheeler
 Christopher White
+David White
 Mats Wichmann
 Truida Wiedijk
 Felix Wiemann

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Sun Jan  9 08:55:46 2011
@@ -31,6 +31,9 @@
 Library
 -------
 
+- Issue #10869: Fixed bug where ast.increment_lineno modified the root
+  node twice.
+
 - Issue #5871: email.header.Header.encode now raises an error if any
   continuation line in the formatted value has no leading white space
   and looks like a header.  Since Generator uses Header to format all


More information about the Python-checkins mailing list