[issue19335] codeop misclassifies incomplete code with 'nonlocal'

Pablo Galindo Salgado report at bugs.python.org
Mon Jun 29 08:55:24 EDT 2020


Pablo Galindo Salgado <pablogsal at gmail.com> added the comment:

> Pablo, correct me if I'm wrong, but I think that the parser has nothing to do with this. It's not the parser that produces this SyntaxError, it's some later compilation phase (I guess symtable creation phase?), which I know very very little about, so I can't really offer an opinion on what can be done.

Yeah, this is correct the parser has nothing to be done with this, what is involved in this is the compiler, as the generated AST looks correct.

>  When the new parser compiles a function, does it know or could it know whether it is nested?

Nop, the parser does not even know what a 'function' is while it parses, as that is only determined in the product of the parser itself: the AST. The piece that understands semantically what a function is and if is nested or not is the compiler.

> Parsing should not care about statement semantics, in that a nonlocal statement should be like any other statement in the parser's point of view.

Yup, I very much agree with this. The parser must not know about the semantics of the AST elements (forcing it to do so will be not only very complex but also will make maintenance much more difficult as the parser will be coupled with the semantics of the language is parsing as opposed to only having to know about the grammar).

> All in all, I think that Nick's hack is the way to go here, since it's comc's responsibility to correctly check if a statement is incomplete, right?

If I understand correctly, Nick is talking about modifying the different iterations for different errors in codeop no?

----------

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


More information about the Python-bugs-list mailing list