homepage

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: Line 0 SyntaxWarning with duplicate global declarations
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: jeffconnelly, nnorwitz, terry.reedy
Priority: normal Keywords:

Created on 2004年02月03日 04:39 by jeffconnelly, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Messages (3)
msg19896 - (view) Author: Jeff Connelly aka shellreef (jeffconnelly) Date: 2004年02月03日 04:39
global a
a = "b"
global a
a.py:0: SyntaxWarning: name 'a' is assigned to before
global declaration
This is a fairly minor bug, however, the message is
misleading (the variable is in fact assigned to both
before and after the global declaration). At least, the
line number should be fixed to refer to the second
declaration, and if possible the error message should
be changed to "duplicate global declaration of 'a'".
P.S.: If "global a" is repeated multiple times, the
error message will be repeated, with the same line
number, and no indication that the warning refers to a
different line.
msg19897 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2004年02月13日 22:47
Logged In: YES 
user_id=593130
>if possible the error message should
be changed to "duplicate global declaration of 'a'".
The ref man does not prohibit duplicate declarations, nor is 
duplication essential to get the misleading line number: 
>>> def f():
... global a
... b = 0
... global b
...
<stdin>:1: SyntaxWarning: name 'b' is assigned to before 
global declaration
It appears that compiler treats additional global declarations 
as continuations of first and only stores one line #, the first, 
for the 'combined' declaration. If code is too difficult to 
change, perhaps ref man could make note of this ;-)
msg19898 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2005年12月19日 04:28
Logged In: YES 
user_id=33168
Fixed for 2.5. Thanks for the bug report.
Committed revision 41767.
History
Date User Action Args
2022年04月11日 14:56:02adminsetgithub: 39894
2004年02月03日 04:39:34jeffconnellycreate

AltStyle によって変換されたページ (->オリジナル) /