A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-November/094263.html below:

[Python-Dev] global statements outside functions/methods should raise SyntaxError

[Python-Dev] global statements outside functions/methods should raise SyntaxError [Python-Dev] global statements outside functions/methods should raise SyntaxErrorEzio Melotti ezio.melotti at gmail.com
Sun Nov 15 20:55:00 CET 2009
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


I opened an issue on the tracker (http://bugs.python.org/issue7329)
and Benjamin suggested to discuss this here.
The test he mentioned is in test_global.py:

    def test4(self):
        prog_text_4 = """\
global x
x = 2
"""
        # this should work
        compile(prog_text_4, "<test string>", "exec")

It just says that "it should work" but it doesn't say /why/.

Any thoughts?

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4