Lysandros Nikolaou <lisandros...@gmail.com> added the comment:

I feel that I wasn't clear at all in my previous responses, so let me try to 
have another go at explaining how I see this:

We have two distinct problems, that are totally unrelated to one another:

1) nonlocal should raise when it's not in a nested function (question for the 
more experienced here: is this the *only* place where nonlocal is allowed?)

2) comc should return None, signifying an incomplete input, when presented with 
the bloack:

def a():
    def b():
        nonlocal c

because c, the variable, could be declared in a, the function, some time after 
the definition of b, the function, is done.

The way I see this, like I have expressed in my previous comments, is that 
whatever solution we come up with should not involve the parser, because it 
should not care about statement semantics. I'm not really sure what the best 
solutions are, but I'd propose the following for the problems I listed above:

1) We should alter code in symtable.c to check whether the namespace in which 
the nonlocal statement appears in is a function block and whether it is nested 
or not.

2) A check for the SyntaxError message to see if it comes from a nonlocal 
statement surely sounds like a hack, but I don't think that's a dealbreaker. 
I'd probably go with this rather than undergoing the effort of exposing the 
indentation stack in Python and then examining it in codeop.

Thoughts?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue19335>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to