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 aronacher
Recipients aronacher, daishiharada, georg.brandl
Date 2008-08-16.12:21:25
SpamBayes Score 1.9953e-06
Marked as misclassified No
Message-id <>
This is actually not a bug.  copy_location does not work recursively. 
For this example it's more useful to use the "fix_missing_locations"
function which traverses the tree and copies the locations from the
parent node to the child nodes:

import ast
a = ast.parse('foo', mode='eval')
x = compile(a, '<unknown>', mode='eval')

class RewriteName(ast.NodeTransformer):
    def visit_Name(self, node):
        return ast.Subscript(
            value=ast.Name(id='data', ctx=ast.Load()),

a2 = ast.fix_missing_locations(RewriteName().visit(a))
Date User Action Args
2008-08-16 12:21:29aronachersetrecipients: + aronacher, georg.brandl, daishiharada
2008-08-16 12:21:29aronachersetmessageid: <>
2008-08-16 12:21:28aronacherlinkissue3530 messages
2008-08-16 12:21:27aronachercreate