Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52684 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2013-08-19 12:04 +0100 |
| Last post | 2013-08-19 12:04 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: NodeTransformer: how to remove nodes? Chris Angelico <rosuav@gmail.com> - 2013-08-19 12:04 +0100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-08-19 12:04 +0100 |
| Subject | Re: NodeTransformer: how to remove nodes? |
| Message-ID | <mailman.23.1376910276.19984.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web