This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Esa.Peuha, Mark.Shannon, RJ722, Rosuav, lys.nikolaou, ncoghlan, pablogsal, r.david.murray, terry.reedy
Date 2020-06-28.16:01:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1593360076.99.0.674746864696.issue19335@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-06-28 16:01:17terry.reedysetrecipients: + terry.reedy, ncoghlan, r.david.murray, Mark.Shannon, Rosuav, Esa.Peuha, lys.nikolaou, pablogsal, RJ722
2020-06-28 16:01:16terry.reedysetmessageid: <1593360076.99.0.674746864696.issue19335@roundup.psfhosted.org>
2020-06-28 16:01:16terry.reedylinkissue19335 messages
2020-06-28 16:01:16terry.reedycreate