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

Terry Reedy tjreedy at udel.edu
Sun Nov 15 21:38:26 CET 2009


Ezio Melotti wrote:
> Python currently accepts global statements at the top level:
>
> 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?

I make the same suggestion a couple of years ago, either this list or 
Py3k list, after newby reported 'problem' on python-list expecting 
module-level global to do something. Guido rejected it on the basis that 
he wanted to minimized differences between module code and function code.



More information about the Python-Dev mailing list