Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #57239
| References | <CAPTjJmpEaQxN10eSU2YzZZ-4wMoT3K=iFBYQqgBx_RZ3AWyfTw@mail.gmail.com> <mailman.1316.1382385139.18130.python-list@python.org> <5265be56$0$29981$c3e8da3$5496439d@news.astraweb.com> <mailman.1332.1382412405.18130.python-list@python.org> <526613ae$0$30000$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2013-10-22 17:24 +1100 |
| Subject | Re: IDLE being too clever checking nonlocal declarations? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1338.1382423051.18130.python-list@python.org> (permalink) |
On Tue, Oct 22, 2013 at 4:57 PM, Steven D'Aprano <steve@pearwood.info> wrote: > 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. Yeah. I came across this as I was knocking together a test for something else, and my work-around was to define the inner function as just "pass", and then go back and edit in the nonlocal declaration after adding the assignment outside. The only problem is that it's syntax-checking something that's only half-entered, and is bombing on it - thus stopping you from typing in the bit that would make it valid. Thanks Terry for the extra info on the tracker issue. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: IDLE being too clever checking nonlocal declarations? Terry Reedy <tjreedy@udel.edu> - 2013-10-21 15:51 -0400
Re: IDLE being too clever checking nonlocal declarations? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-21 23:52 +0000
Re: IDLE being too clever checking nonlocal declarations? Terry Reedy <tjreedy@udel.edu> - 2013-10-21 23:26 -0400
Re: IDLE being too clever checking nonlocal declarations? Steven D'Aprano <steve@pearwood.info> - 2013-10-22 05:57 +0000
Re: IDLE being too clever checking nonlocal declarations? Chris Angelico <rosuav@gmail.com> - 2013-10-22 17:24 +1100
Newline in bash, was Re: IDLE being too clever checking nonlocal declarations? Peter Otten <__peter__@web.de> - 2013-10-22 09:20 +0200
csiph-web