Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.ecp.fr!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.86.MISMATCH!newsfeed.xs4all.nl!newsfeed3.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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'compiler': 0.07; 'namespace': 0.09; 'python:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; "'q'": 0.16; 'declaration': 0.16; 'kasper': 0.16; 'retrieving': 0.16; 'side.': 0.16; 'weird.': 0.16; 'weird': 0.16; 'seems': 0.21; 'otherwise,': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'of.': 0.24; 'cheers,': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'purely': 0.31; 'maybe': 0.34; 'could': 0.34; 'agree': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'how': 0.40; 'even': 0.60; 'around.': 0.60; 'affect': 0.61; "you're": 0.61; 'information': 0.63; 'more': 0.64; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'side': 0.67; 'transfer': 0.82 Date: Wed, 26 Nov 2014 11:40:12 +0000 From: Kasper Peeters To: Chris Angelico Subject: Re: PyEval_GetLocals and unreferenced variables In-Reply-To: References: <20141126102257.141b108f@klug> <20141126104628.78ed4022@klug> X-Mailer: Claws Mail 3.10.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417002046 news.xs4all.nl 2844 [2001:888:2000:d::a6]:56463 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81561 > To be honest, that's just made it even more weird :) You're creating > something in a local namespace that the Python compiler isn't aware > of. Yes, I agree that retrieving the locals with PyEval_GetLocals and then sticking something in there on the C side is weird. I wouldn't say that the Python compiler is not aware of it though (I could ask my question purely in Python: how do I check in the scope of fun2 whether 'q' is available in the outer scope without actually using it). > I wonder, would a 'nonlocal q' declaration inside fun2 affect things > any? Yes, that pulls in 'q', but I would like to do that 'nonlocal q' on the C side. If I have to write 'nonlocal q' inside fun2 then I can also pull in 'q' using any other reference to 'q'. > Otherwise, maybe there's some completely different way to transfer > information around. Using locals in this way seems fraught with peril. There might very well be... Cheers, Kasper