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 <1218889289.0.0.3348723151.issue3530@psf.upfronthosting.co.za>
In-reply-to
Content
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()),
            slice=ast.Index(value=ast.Str(s=node.id)),
            ctx=node.ctx
        )

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