Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52684
| References | <CAM5eX4D1KB8dVgsR=6ZPjcuhwehN4UR0YQtvNgJ+m-Acs1VoDg@mail.gmail.com> |
|---|---|
| Date | 2013-08-19 12:04 +0100 |
| Subject | Re: NodeTransformer: how to remove nodes? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.23.1376910276.19984.python-list@python.org> (permalink) |
On Mon, Aug 19, 2013 at 10:19 AM, Tobias Müller <to.mueller13@gmail.com> wrote:
> Hi
>
> I'm facing an issue with NodeTransformer, a tool used for Python AST
> manipulations.
>
> Last week I posted on stackoverflow.com, but there are no responses yet.
> Maybe someone reading the mailing list can have a look and leave me a
> response here or over there?
>
> http://stackoverflow.com/questions/18275662/python-nodetransformer-how-to-remove-nodes
I'm not familiar with NodeTransformer, but by the look of things, your
visit_For is being called (indirectly) by your own iterate_children,
which then ignores the return value. To apply changes like this,
either remove your definition of generic_visit, or have it pass
through to super():
def generic_visit(self, node):
"""
default behaviour
"""
print("visiting: "+node.__class__.__name__)
return super().generic_visit(node)
It's the code for NodeTransformer.generic_visit that does the
replacements (check out Lib/ast.py - it's down the very bottom in the
3.3 that I have), so if you bypass that, no replacement happens.
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: NodeTransformer: how to remove nodes? Chris Angelico <rosuav@gmail.com> - 2013-08-19 12:04 +0100
csiph-web