This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients aronacher, benjamin.peterson, daishiharada, docs@python, georg.brandl, terry.reedy
Date 2015-06-29.20:44:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I am reopening this as a doc bug because RewriteName is a copy (with 'ast.' prefixes added) of a buggy example in the doc. The bug is that the new .value Name and Str attributes do not get the required 'lineno' and 'col_offset' attributes.  As Armin said, copy_location is not recursive and does not fix children of the node it fixes.  Also, the recursive .visit method does not recurse into children of replacement nodes (and if it did, the new Str node would still not be fixed).

The fix could be to reuse the Name node and add another copy_location call: the following works.

    def visit_Name(self, node):
        return ast.copy_location(
                    ast.Str(, node)),

but I think this illustrates that comment in the fix_missing_locations() entry that locations are "tedious to fill in for generated nodes".  So I think the doc fix should use Armin's version of RewriteName and say to call fix_missing_locations on the result of .visit if new nodes are added.  (I checked that his code still works in 3.5).

The entry for NodeTransformer might mention that .visit does not recurse into replacement nodes.

The missing lineno error came up in this python-list thread:
Date User Action Args
2015-06-29 20:44:43terry.reedysetrecipients: + terry.reedy, georg.brandl, daishiharada, benjamin.peterson, aronacher, docs@python
2015-06-29 20:44:43terry.reedysetmessageid: <>
2015-06-29 20:44:43terry.reedylinkissue3530 messages
2015-06-29 20:44:43terry.reedycreate