[New-bugs-announce] [issue7329] global statements outside functions/methods should raise SyntaxError

Ezio Melotti report at bugs.python.org
Sun Nov 15 16:10:27 CET 2009


New submission from Ezio Melotti <ezio.melotti at gmail.com>:

Python currently accepts global statements at the top level:
>>> global foo
>>>

Beside being a meaningless operation, this might lead unexperienced user
to make mistakes like:
>>> foo = 5
>>> global foo # make foo global
>>> def func():
...   print foo # access the global foo
...
>>> func()
5
>>> # it works!

"global foo" should raise a SyntaxError, similarly to what already
happens with "return":
>>> return foo
  File "<stdin>", line 1
SyntaxError: 'return' outside function

----------
components: Interpreter Core
messages: 95299
nosy: benjamin.peterson, ezio.melotti
priority: normal
severity: normal
status: open
title: global statements outside functions/methods should raise SyntaxError
type: feature request
versions: Python 2.7, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7329>
_______________________________________


More information about the New-bugs-announce mailing list