IDLE being too clever checking nonlocal declarations?
Terry Reedy
tjreedy at udel.edu
Mon Oct 21 15:51:56 EDT 2013
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.
> In interactive command-line Python, this doesn't throw an error,
> it works fine if the name is used later:
>
>>>> def a():
> def b():
> nonlocal q
> q+=1
I verified that interactive Python also syntax checks each line as
entered, even for compound statements. Details should be left to the
tracker issue you raised.
--
Terry Jan Reedy
More information about the Python-list
mailing list