[issue19335] codeop misclassifies incomplete code with 'nonlocal'

Rahul Jha report at bugs.python.org
Mon Jun 29 13:34:51 EDT 2020


Rahul Jha <rahul722j at gmail.com> added the comment:

> That may actually be another alternative: instead of doing the "try
> appending newlines and see if it works or generates different errors",
> we may be able to switch to the tokenizer if the initial compilation
> fails and check for hanging INDENT tokens (i.e. INDENTS without a
> corresponding DEDENT). That would get us much closer to what the real
> eval loop is doing.

>From what I understand, "checking for two or more hanging INDENTS" and, "hardcoding a check for nonlocal SyntaxErrors in codeop._maybe_compile" are two different solutions, right?  If yes, do we have an answer to which one of them is more cleaner, and henceforth, the preferable solution?

I, personally, like the idea of checking INDENTS primarily because of it's reduced specificity, but I am in no position to comment on this (I already kinda did ':D), and you folks know better! For all we know, we should be optimizing for specificity.

Also, reading Nick's comments and the comc's code, gives me the feeling that a fix for this wouldn't require drastic changes.  I'm slowly starting my journey with CPython, and I'd like to contribute a patch if that is the case. Thanks!

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue19335>
_______________________________________


More information about the Python-bugs-list mailing list