Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'subject:IDLE': 0.04; 'interpreter': 0.05; 'that?': 0.05; 'continuation': 0.07; 'differently': 0.07; 'see.': 0.07; "'...'": 0.09; 'agree,': 0.09; 'line:': 0.09; 'newline': 0.09; 'raises': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terminates': 0.09; 'undefined': 0.09; 'python': 0.11; 'def': 0.12; 'bug': 0.12; 'jan': 0.12; 'thread': 0.14; 'windows': 0.15; "'c'": 0.16; "'q'": 0.16; '(source': 0.16; 'a():': 0.16; 'b():': 0.16; 'bind': 0.16; 'binding.': 0.16; 'bug:': 0.16; 'c():': 0.16; 'idle.': 0.16; 'marker': 0.16; 'quoted': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subclasses': 0.16; 'subject:too': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'typing': 0.19; 'unlike': 0.19; 'command': 0.22; '>>>': 0.22; 'input': 0.22; 'issue.': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'lets': 0.24; 'replace': 0.24; 'fine': 0.24; 'mon,': 0.24; 'question': 0.24; 'source': 0.25; '(see': 0.26; 'tracker': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'chris': 0.29; 'url:bugs': 0.29; 'am,': 0.29; '(like': 0.30; 'skip:( 20': 0.30; 'code': 0.31; 'lines': 0.31; '"",': 0.31; "d'aprano": 0.31; 'implied': 0.31; 'steven': 0.31; 'file': 0.32; 'this.': 0.32; 'regular': 0.32; 'url:python': 0.33; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'idle': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'too': 0.37; 'level': 0.37; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'rather': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'received:173': 0.61; 'complete': 0.62; 'such': 0.63; 'more': 0.64; 'line,': 0.68; 'compiles': 0.84; 'ii.': 0.84; 'received:fios.verizon.net': 0.84; 'subject:being': 0.84; 'valid)': 0.84; '2013,': 0.91; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: IDLE being too clever checking nonlocal declarations? Date: Mon, 21 Oct 2013 23:26:28 -0400 References: <5265be56$0$29981$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-59-117-133.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 In-Reply-To: <5265be56$0$29981$c3e8da3$5496439d@news.astraweb.com> 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: 81 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1382412405 news.xs4all.nl 15881 [2001:888:2000:d::a6]:57816 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57226 On 10/21/2013 7:52 PM, Steven D'Aprano wrote: > On Mon, 21 Oct 2013 15:51:56 -0400, Terry Reedy wrote: > >> On 10/21/2013 11:06 AM, Chris Angelico wrote: >>> Try typing this into IDLE: >>> >>>>>> def a(): >>> def b(): >>> nonlocal q >>> SyntaxError: no binding for nonlocal 'q' found >> >> If you submit those three lines to Python from the command line, that is >> what you see. > > Arguably, that's also too strict, As I quoted from the doc, it is an error for a program to contain a nonlocal with no referent. The reason is one only needs nonlocal to bind and unlike with 'global newname', it would be undefined where to do the binding. def a(): def b(): def c(): nonlocal q; q = 1 Where does q go? Replace nonlocal with global and there is no issue. > but these *four* lines work fine interactively: > > py> def a(): > ... def b(): > ... nonlocal q > ... q = 1 Chris had something like this. > and also from the command line: > > > [steve@ando ~]$ python3.3 -c "def a(): >> def b(): >> nonlocal q >> q = 1 >> " What system lets you do that? (See other thread about Windows not allowing that, because newline terminates the command even after ".) Is '>' a line continuation marker (like '...' in Python)? > so it should also work in IDLE. I agree, and implied such on the tracker issue http://bugs.python.org/issue19335 The question is "what does Idle do differently from the C level interpreter". The answer is that is subclasses the Python-coded code.InteractiveInterpreter. Call this II. II.runsource compiles *cumulative* source ultimately with the Python-coded codeop._maybe_compile, which returns a code object (source complete and valid) or None (source incomplete) or raises (source complete but not valid). The bug is seeing the three line input as 'complete but invalid' rather than as 'incomplete' (as the regular interpreter must). To verify that this is not an Idle bug: C:\Programs\Python33>python -m code Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> def a(): ... def b(): ... nonlocal c File "", line None SyntaxError: no binding for nonlocal 'c' found There is a bit more on the tracker. -- Terry Jan Reedy