Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52796

Re: NodeTransformer: how to remove nodes?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <to.mueller13@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'yet.': 0.04; '"""': 0.07; "'',": 0.07; '[0,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'posted': 0.15; 'ast': 0.16; 'behaviour.': 0.16; 'overriding': 0.16; 'subject:remove': 0.16; 'there?': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.18; 'module': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'replace': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'source': 0.25; '&gt;': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'leave': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'went': 0.31; "skip:' 10": 0.31; 'along.': 0.31; 'class': 0.32; 'skip:m 30': 0.32; 'url:python': 0.33; 'maybe': 0.34; 'tool': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'too': 0.37; 'list': 0.37; 'skip:& 10': 0.38; 'generic': 0.38; 'issue': 0.38; 'mailing': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'further': 0.61; 'skip:n 10': 0.64; 'more': 0.64; 'total': 0.65; 'here': 0.66; 'otten': 0.84; 'subject:skip:N 10': 0.84; 'responses': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=hPX9rUeNF7axA7MiYvTlV4ph1Gvfd2JjiUeQ7Ear4+0=; b=i2f3BHGeefX9i1NyJZeEryz8oNNE2L/KJz/grz855ec7AJGHjnmoVjnT95NRB/B7Dy mSqxx5+TikFZBglZkOAMx0X0KQRWRL0F4Rqhk+jYI3OoP+AXw9XqHz6zdYVemxw4P9C+ LcaDMy8058sRMigfxlLiGJBgMUgD55VX8A9yAte1bs7GcMWWGWocVhwTdZOQ71F+3ImR wzVScnmCX1XEMLXhOz3GIp8gQzamN8Lnye1ah+qchPQIvI3zkS45yLDP3O/C9qI6BHNZ kfFybwG2XTqNwM091hejDnWOon5Ta5Om4vFA14INLU9tUJ7ecQUr7yu7l4z+5jGisH6h 0S7Q==
MIME-Version 1.0
X-Received by 10.15.35.196 with SMTP id g44mr11088438eev.18.1377096399901; Wed, 21 Aug 2013 07:46:39 -0700 (PDT)
In-Reply-To <kusv2c$q1f$1@ger.gmane.org>
References <CAM5eX4D1KB8dVgsR=6ZPjcuhwehN4UR0YQtvNgJ+m-Acs1VoDg@mail.gmail.com> <kusv2c$q1f$1@ger.gmane.org>
Date Wed, 21 Aug 2013 16:46:39 +0200
Subject Re: NodeTransformer: how to remove nodes?
From Tobias Müller <to.mueller13@gmail.com>
To Peter Otten <__peter__@web.de>
Content-Type multipart/alternative; boundary=089e0160c1a0bcf82b04e4763dc3
X-Mailman-Approved-At Wed, 21 Aug 2013 22:48:19 +0200
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.106.1377118100.19984.python-list@python.org> (permalink)
Lines 133
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377118100 news.xs4all.nl 15939 [2001:888:2000:d::a6]:48687
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52796

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Thanks Chris and Peter.

I already went further along. No more issues so far.



2013/8/19 Peter Otten <__peter__@web.de>

> Tobias Müller wrote:
>
> > 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
>
> As Chris says, you are overriding too much of the generic behaviour. Here
> is
> a working demo:
>
> import ast
>
> class MyTransformer(ast.NodeTransformer):
>     def visit_For(self, node):
>         """
>         For nodes: replace with nothing
>         """
>         print("removing a For node")
>         return None
>
>
> source = """
> l = [0, 1, 2, 3]
>
> total = 0
>
> for i in l:
>     total += i
>
> print(total)
> """
>
> transformer = MyTransformer()
> module = ast.parse(source)
> transformer.visit(module)
> codeobj = compile(module, '<string>', 'exec')
> exec(codeobj)
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: NodeTransformer: how to remove nodes? Tobias Müller <to.mueller13@gmail.com> - 2013-08-21 16:46 +0200

csiph-web