Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'concurrently': 0.07; 'present,': 0.07; 'cc:addr:python-list': 0.09; 'generators': 0.09; 'iterate': 0.09; 'runtime': 0.09; 'thrown': 0.09; 'python': 0.10; 'exception': 0.13; 'stack': 0.13; 'def': 0.13; 'subsequent': 0.15; 'value.': 0.15; 'cause.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'generator.': 0.16; 'threads': 0.16; 'trace.': 0.16; 'traceback.': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'instance,': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'affected': 0.22; "aren't": 0.22; 'trace': 0.22; 'header:In-Reply-To:1': 0.24; 'appear': 0.26; 'chris': 0.26; 'figure': 0.27; 'error': 0.27; 'fri,': 0.27; 'room': 0.27; 'message-id:@mail.gmail.com': 0.27; 'yield': 0.27; 'function': 0.28; 'idea': 0.28; 'record': 0.29; 'itself,': 0.29; 'strings,': 0.29; 'sure,': 0.29; 'subject:/': 0.30; 'that.': 0.30; "can't": 0.32; 'driven': 0.33; 'jump': 0.33; 'raised': 0.33; 'traceback': 0.33; 'case,': 0.34; 'this?': 0.34; 'that,': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'next': 0.35; 'could': 0.35; 'something': 0.35; "isn't": 0.35; 'but': 0.36; 'list,': 0.36; 'should': 0.36; 'possible.': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'one,': 0.37; 'thought': 0.37; 'list.': 0.37; 'things': 0.38; 'stuff': 0.38; 'mean': 0.38; 'why': 0.39; 'sure': 0.39; "didn't": 0.39; 'where': 0.40; 'still': 0.40; 'some': 0.40; 'back': 0.62; 'yes': 0.62; 'here.': 0.62; 'matter': 0.63; 'more': 0.63; 'different': 0.63; 'information': 0.63; 'records': 0.70; 'jul': 0.72; 'chrisa': 0.84; 'imagine,': 0.84; "it'd": 0.84; 'pardon': 0.84; 'to:none': 0.91; 'from.': 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:cc :content-type; bh=XF5nVJ2ysiSe02KerdbXQo7NAU+BXPvgrgtQazyvarI=; b=1BB/B+U5CkvSjVWJ4lwOUWjqWS1olNOrm9UY8+wuqv0T4wUljpcjjraGHknibOsVAn sEqPHCwpJCfRm9u3mCQNk40+sqZoF8VaEGbeg14xySO35dCfisH1YC30DyMgTtpZaYW9 536uSjM5biydNSVYnp62lorSNCuLwGyRuSUu0kNPQshdIkyHZktH+VT32YAFMZmo94qb x6ggxyL1kn555FhEkp9ymqK81pcbapD4fVam7r+sjD1jzfCyc2tMkUplkUA8vbTT9cJ4 lGlUDSUUeAXOhxc9ZoTwJ9SsWpHBRsNaibmRmEKXg1Rk/0Emo5q84ct27ZtYHUImoXtM bh6g== MIME-Version: 1.0 X-Received: by 10.50.36.72 with SMTP id o8mr10194882igj.16.1437133797367; Fri, 17 Jul 2015 04:49:57 -0700 (PDT) In-Reply-To: <55A8EA7D.2040005@rece.vub.ac.be> References: <87bnff1eks.fsf@jester.gateway.sonic.net> <87d1zunctp.fsf@elektro.pacujo.net> <87k2u2eu67.fsf@elektro.pacujo.net> <55A51662.4090007@rece.vub.ac.be> <55A75DE0.1070101@rece.vub.ac.be> <55A7B80B.6090905@rece.vub.ac.be> <55A7C094.7060604@rece.vub.ac.be> <55A8DD75.5000403@rece.vub.ac.be> <55A8EA7D.2040005@rece.vub.ac.be> Date: Fri, 17 Jul 2015 21:49:57 +1000 Subject: Re: Possibly Pythonic Tail Call Optimization (TCO/TRE) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437133800 news.xs4all.nl 2955 [2001:888:2000:d::a6]:52406 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:94007 On Fri, Jul 17, 2015 at 9:43 PM, Antoon Pardon wrote: > On 07/17/2015 01:05 PM, Chris Angelico wrote: >> On Fri, Jul 17, 2015 at 8:48 PM, Antoon Pardon >> wrote: >>> Just wondering, are traceback records of generators available? They are >>> if an exception is raised in the generator itself, but what if an exception >>> is raised in the loop that is driven by a generator. They don't appear in >>> the standard stack trace. >> Not sure what you mean here. Something like this? >> >> def gen(): >> yield stuff >> yield more stuff >> >> for stuff in gen(): >> bomb with exception >> >> The error didn't happen in the generator, so I wouldn't expect to see >> it in the traceback. > > Yes something like that. And I wouldn't expect it either but if it > is not present, is it because nobody thought about it or because it > is a bad idea or an idea difficult to implement? > >> There's still room for the cause of an error to >> not be in the traceback; imagine, for instance, a function that >> populates a concrete list, and then you iterate over the list. If that >> function sticks a None into the list and the subsequent processing is >> expecting all strings, that's going to bomb, but then you have to >> figure out where the None came from. If the traceback could include >> that, it'd be great, but some things aren't possible. > > Sure, but in this case, the generator is still active. The Runtime > would be able to jump to and somehow activates it's stack record > for the next value. So why would we expect it to be impossible to > include this trace back record in a stack trace? Python could also give you stack traces for any other threads that are concurrently running, on the off-chance that one of them affected it. But the only influence the generator has on the loop is to yield a value or signal termination; if an exception is thrown in the loop itself, the local name 'stuff' should have all the information about that cause. Python isn't a mind-reader, no matter how much it may look like one, and it can't know that this function's return value should be shown as part of a completely different function's stack trace. ChrisA