Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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; 'subject:IDLE': 0.04; 'cpython': 0.05; 'interpreter': 0.05; 'that?': 0.05; '*not*': 0.07; 'continuation': 0.07; 'see.': 0.07; 'strict': 0.07; "'...'": 0.09; 'bash': 0.09; 'newline': 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; 'way:': 0.09; 'python': 0.11; 'def': 0.12; 'bug': 0.12; 'thread': 0.14; 'windows': 0.15; "'q'": 0.16; 'a():': 0.16; 'b():': 0.16; 'bash,': 0.16; 'bind': 0.16; 'binding.': 0.16; 'escapes': 0.16; 'marker': 0.16; 'newline,': 0.16; 'quoted': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'reedy': 0.16; 'said.': 0.16; 'sees': 0.16; 'subject:too': 0.16; 'syntaxerror:': 0.16; 'exception': 0.16; 'followed': 0.16; 'wrote:': 0.18; 'module': 0.19; 'typing': 0.19; 'unlike': 0.19; 'working.': 0.19; 'seems': 0.21; 'command': 0.22; '>>>': 0.22; 'rules': 0.22; 'saying': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'lets': 0.24; 'mon,': 0.24; '(see': 0.26; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'raise': 0.29; '(like': 0.30; 'characters': 0.30; "i'm": 0.30; 'lines': 0.31; 'usually': 0.31; '>>>>': 0.31; "d'aprano": 0.31; 'linux.': 0.31; 'steven': 0.31; 'allows': 0.31; 'another': 0.32; 'linux': 0.33; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'idle': 0.36; 'subject:?': 0.36; 'should': 0.36; 'too': 0.37; 'being': 0.38; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'letters': 0.60; 'strictly': 0.61; 'different': 0.65; 'line,': 0.68; 'special': 0.74; 'analysis': 0.75; 'subject:being': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Newline in bash, was Re: IDLE being too clever checking nonlocal declarations? Date: Tue, 22 Oct 2013 09:20:15 +0200 Organization: None References: <5265be56$0$29981$c3e8da3$5496439d@news.astraweb.com> <526613ae$0$30000$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084bd9f.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 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: 86 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1382426425 news.xs4all.nl 15944 [2001:888:2000:d::a6]:57737 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57241 Steven D'Aprano wrote: > On Mon, 21 Oct 2013 23:26:28 -0400, Terry Reedy wrote: > >> 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. > > Yep, I got that, but what I'm saying is that it is too strict to raise > the exception at the point where it sees "nonlocal q". The CPython > interpreter allows q to be defined inside function a but after function > b, e.g. this is allowed: > > def a(): > def b(): > nonlocal q > q += 1 > q = 2 # <======= > > > If IDLE and the code.py module requires q to be strictly defined before > function b, then it is too strict. Your analysis of the bug as being in > code.py seems plausible. > > > >>> [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)? > > Yes, sorry I should have said. That's bash, under Linux. > > Here's another way: > > > steve@runes:~$ python3.3 -c "def a():^M def b():^M nonlocal q^M > q=1^Mprint(a() is None)" > True > > > Still bash under Linux (a different machine), the ^M is *not* a pair of > characters ^ followed by M but an actually newline, generated by typing > Ctrl-V Enter (that's the ENTER key, not the letters E n t e r). > > In theory I should be able to get something working with \n escapes > instead of ^M, but I can't get it working. But I'm not an expect at bash's > arcane rules for quoting and escaping special characters. I usually just hit Return... $ python3.3 -c "def a(): > def b(): > nonlocal q > q = 1 > print(a() is None)" True but you prompted me to google: $ python3.3 -c $'def a():\n def b():\n nonlocal q\n q = 1\nprint(a() is None)' True