[issue30887] Syntax checking confuses Try: class_instance_name as ... is used before glabal declaration

Steven D'Aprano report at bugs.python.org
Sun Jul 9 22:42:51 EDT 2017


Steven D'Aprano added the comment:

Please copy and paste (don't retype from memory!) the *exact* error you are getting.

You should be seeing something like:

SyntaxWarning: name 'current_user' is used prior to global declaration

(at least that's the warning I'm getting in Python 3.5), which is correct behaviour. The name is used prior to the global declaration.

The Python interpreter is now discouraging the use of the "global" keyword anywhere except at the top of the function. (It may some day become an error.)

If your code is unindented module-level code, as your code snippet suggests, you don't need the global declaration since current_user is automatically global.

If it is function-level code, then move the global declaration to the top of the function, as the SyntaxWarning suggests.

I don't believe this is a bug, I believe that what you are seeing is expected, so I am closing this bug report. If I have misunderstood what you are experiencing, then please re-open the ticket and give us some more information. Preferably give us some code that we can run that demonstrates the error. (Since the error doesn't have anything to do with flask, the `import flask` line is unnecessary.)

----------
nosy: +steven.daprano

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


More information about the Python-bugs-list mailing list