Author lys.nikolaou
Recipients Esa.Peuha, Mark.Shannon, RJ722, Rosuav, cheryl.sabella, lys.nikolaou, mbussonn, ncoghlan, pablogsal, r.david.murray, terry.reedy
Date 2020-06-30.16:21:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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.

Date User Action Args
2020-06-30 16:21:42lys.nikolaousetrecipients: + lys.nikolaou, terry.reedy, ncoghlan, r.david.murray, Mark.Shannon, Rosuav, Esa.Peuha, mbussonn, cheryl.sabella, pablogsal, RJ722
2020-06-30 16:21:41lys.nikolaousetmessageid: <>
2020-06-30 16:21:41lys.nikolaoulinkissue19335 messages
2020-06-30 16:21:41lys.nikolaoucreate