[Python-Dev] cpython: Issue #27999: Make "global after use" a SyntaxError, and ditto for nonlocal.

Christian Heimes christian at python.org
Mon Sep 12 06:24:06 EDT 2016


On 2016-09-12 11:46, Ivan Levkivskyi wrote:
> Christian,
> 
> When I wrote this, my intention was like: cur & DEF_LOCAL is a "more
> serious" error, so that if both errors are made in the same statement:
> def f():
>     x: int = 5
>     global x
> 
> "SyntaxError: global after assignment" will be reported. The same logic
> applies to nonlocal.

Hi Ivan,

thanks for your explanation. The code looks suspicious. Can you please
provide a patch that makes it more obvious, e.g. either by using if /
else if / else or a comment?

Christian


More information about the Python-Dev mailing list