Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'source.': 0.05; 'none)': 0.07; 'ast': 0.09; 'typed': 0.09; 'def': 0.13; 'interpreter': 0.15; 'arg):': 0.16; 'fits': 0.16; 'thought.': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'work,': 0.21; 'code.': 0.23; 'thus': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'right.': 0.27; 'see,': 0.27; "skip:' 10": 0.28; 'initial': 0.28; 'code': 0.30; 'guess': 0.31; 'source': 0.33; 'definition': 0.34; 'received:10.0': 0.34; 'so,': 0.35; 'best,': 0.35; 'could': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'turned': 0.38; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'charset:windows-1252': 0.62; 'ha,': 0.84 Date: Thu, 10 Sep 2015 20:45:20 +0200 From: "Sven R. Kunze" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Context-aware return References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> <55F1C5D6.7020202@mail.de> <85r3m66t0m.fsf@benfinney.id.au> <55F1CD23.5060009@mail.de> In-Reply-To: <55F1CD23.5060009@mail.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 1016 X-purgate-ID: 154282::1441910723-000007B2-EA7EA020/0/0 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441910725 news.xs4all.nl 23766 [2001:888:2000:d::a6]:56944 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96287 On 10.09.2015 20:34, Sven R. Kunze wrote: > You are right. I turned out to me harder that I first thought. > > My initial guess was like: use AST. But now I see, it would be hard to > get the source code. > > So, what actually could work, would be faking the interactive > interpreter wrapping it up and thus have control over the source code > typed in. Ha, got it: sys.settrace >>> def traceit(frame, event, arg): ... return traceit >>> sys.settrace(traceit) >>> a=1 (, 'call', None) (, 'line', None) (, 'return', (u'a=1\n', 4)) (, 'call', None) (, 'line', None) (, 'return', None) There you got the source. The use an AST to find out whether the line fits your definition of 'interactive'. That should only be necessary when the top frame is interactive. Best, Sven