[Python-Dev] Make "global after use" a SyntaxError

Ivan Levkivskyi levkivskyi at gmail.com
Wed Sep 7 10:10:05 EDT 2016


Hi all,

The documentation at https://docs.python.org/3/reference/simple_stmts.html
says that:

"Names listed in a global statement must not be used in the same code block
textually preceding that global statement"

But then later:

"CPython implementation detail: The current implementation does not enforce
the two restrictions,
but programs should not abuse this freedom, as future implementations may
enforce them..."

Code like this

def f():
    x = 1
    global x

gives SyntaxWarning for several releases, maybe it is time to make it a
SyntaxError?

(I have opened an issue for this http://bugs.python.org/issue27999 I will
submit a patch soon).

--
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20160907/ad0eaba0/attachment.html>


More information about the Python-Dev mailing list