Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'yet.': 0.04; '"""': 0.07; 'happens.': 0.09; 'things,': 0.09; 'python': 0.11; 'def': 0.12; 'changes': 0.15; 'posted': 0.15; 'ast': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:remove': 0.16; 'there?': 0.16; 'wrote:': 0.18; 'value.': 0.19; 'aug': 0.22; 'mon,': 0.24; 'pass': 0.26; 'skip:" 20': 0.27; 'header:In-Reply- To:1': 0.27; 'leave': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'maybe': 0.34; 'tool': 0.35; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:?': 0.36; 'list': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'mailing': 0.39; 'either': 0.39; 'called': 0.40; 'remove': 0.60; 'skip:n 10': 0.64; 'here': 0.66; 'bottom': 0.67; 'default': 0.69; 'replacements': 0.84; 'subject:skip:N 10': 0.84; 'responses': 0.93; '2013': 0.98 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 :content-type:content-transfer-encoding; bh=H0WCAdL1EevmmUSjotWuuhUSlvGb0ZzG/qyg3SN/xjc=; b=bwcSx9UvHBwe8qy3zhpe+YlNsgwJZS5MLvC/Do/a8UD2ZMFfKXB+KMxg4h5Q8PHn/6 DNMjtBmTht/hAnhn1UoDJuWd6eNUpUhr8HD2HkXyyUMFRDqA2bZUKgRQG9MWjhoGdZqg QIzbfpzahaPfLIFAc7iPlwuCg/+BUV8HEghTqMVPdZz/ASNg6VinBVpd7jsBavJ2SzgF hZQLmhNE6p9jXcVG5YukB5Zik4EjZalN3jpv6q8mIu3knM1xv7T55YxM3XuojePnbDZE nRFOJ+U9fLPDNE8fKAMvz8J9dcBMu3prfRg4HWsVRfJ4HaM2T8vKq7iOo4we0sOt/Nzo enHw== MIME-Version: 1.0 X-Received: by 10.58.146.71 with SMTP id ta7mr1610931veb.23.1376910267518; Mon, 19 Aug 2013 04:04:27 -0700 (PDT) In-Reply-To: References: Date: Mon, 19 Aug 2013 12:04:27 +0100 Subject: Re: NodeTransformer: how to remove nodes? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376910276 news.xs4all.nl 15890 [2001:888:2000:d::a6]:59698 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52684 On Mon, Aug 19, 2013 at 10:19 AM, Tobias M=FCller = 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