Message372522
Pablo and Lysandros: this issue is about a corner-case bug in either compile(,,'single') or its use by REPL and codeop._maybe_compile (comc). What do either of you think? Can the new parser handle it better?
Should we just add the hack suggested by Nick in msg200936 or is there a better solution? Is interactive mode python calling compile() differently? Or is it doing a check that could be incorporated into compile? (Perhap after correction, see below.)
The issue above is about interactive entry of
def a():
def b():
nonlocal c
REPL does not raise SyntaxError, comc does. Not raising is correct here because additional lines added to the nonlocal context may make the code valid.
Additional experiment: the same is true (comc raises, REPL not) for
def a():
nonlocal c
Here, REPL not raising (until a blank is entered) could be considered a glitch because there is no pending nonlocal context to be completed. Though raising later than necessary is better than raising too soon. Nick's hack (and the REPL) could check that there are at least 2 pending indents.
When the new parser compiles a function, does it know or could it know whether it is nested? It should in that the legal grammer (use of nonlocal) is different. |
|
Date |
User |
Action |
Args |
2020-06-28 16:01:17 | terry.reedy | set | recipients:
+ terry.reedy, ncoghlan, r.david.murray, Mark.Shannon, Rosuav, Esa.Peuha, lys.nikolaou, pablogsal, RJ722 |
2020-06-28 16:01:16 | terry.reedy | set | messageid: <1593360076.99.0.674746864696.issue19335@roundup.psfhosted.org> |
2020-06-28 16:01:16 | terry.reedy | link | issue19335 messages |
2020-06-28 16:01:16 | terry.reedy | create | |
|