Terry J. Reedy <tjre...@udel.edu> added the comment:

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.

----------
nosy: +lys.nikolaou, pablogsal
versions: +Python 3.10 -Python 2.7, Python 3.3, Python 3.4

_______________________________________
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