This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Confusing error message for top global
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: jhylton Nosy List: jhylton, prescod
Priority: high Keywords:

Created on 2001-04-13 22:21 by prescod, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (2)
msg4243 - (view) Author: Paul Prescod (prescod) * (Python triager) Date: 2001-04-13 22:21
Call this test.py:

abc = 5
global abc
abc = 6

It is probably illegal to have a global at the top-
level but the error message prdocued is:

SyntaxWarning: name 'abc' is assigned to before global 
declaration

That's technically true but the real problm is that 
global statements should not be allowed outside of 
functions.
msg4244 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2001-04-13 22:50
Logged In: YES 
user_id=31392

Your complain isn't with the error message per se.  It is
correct.  You should not assign to a variable before the
global statement.

Your complaint is that you would *also* like to see a
warning or error about global statement at the top of a
module.  I would too, but... The compiled code might be
executed in a function body with exec, where the global
statement would be meaningful.

If you can think of a way to distinguish these two cases,
re-open the bug report.
History
Date User Action Args
2022-04-10 16:03:57adminsetgithub: 34323
2001-04-13 22:21:40prescodcreate