[issue3530] ast.NodeTransformer bug

2008-08-16 Thread Benjamin Peterson

Changes by Benjamin Peterson <[EMAIL PROTECTED]>:


--
resolution:  -> invalid
status: open -> closed

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3530] ast.NodeTransformer bug

2008-08-16 Thread Armin Ronacher

Armin Ronacher <[EMAIL PROTECTED]> added the comment:

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, '', 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))

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3530] ast.NodeTransformer bug

2008-08-11 Thread Georg Brandl

Changes by Georg Brandl <[EMAIL PROTECTED]>:


--
nosy: +aronacher, georg.brandl

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3530] ast.NodeTransformer bug

2008-08-08 Thread daishi

New submission from daishi <[EMAIL PROTECTED]>:

I am testing python 2.6 from SVN version: 40110

I tried the following, based on the documentation
and example in the ast module. I would expect the
second 'compile' to succeed also, instead of
throwing an exception.

Python 2.6b2+ (unknown, Aug  6 2008, 18:05:08) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> a = ast.parse('foo', mode='eval')
>>> x = compile(a, '', mode='eval')
>>> class RewriteName(ast.NodeTransformer):
... def visit_Name(self, node):
... return ast.copy_location(ast.Subscript(
... value=ast.Name(id='data', ctx=ast.Load()),
... slice=ast.Index(value=ast.Str(s=node.id)),
... ctx=node.ctx
... ), node)
... 
>>> a2 = RewriteName().visit(a)
>>> x2 = compile(a2, '', mode='eval')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: required field "lineno" missing from expr
>>>

--
components: Library (Lib)
messages: 70923
nosy: daishiharada
severity: normal
status: open
title: ast.NodeTransformer bug
versions: Python 2.6

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com