[ python-Bugs-889500 ] Line 0 SyntaxWarning with duplicate global declarations

SourceForge.net noreply at sourceforge.net
Fri Feb 13 17:47:12 EST 2004


Bugs item #889500, was opened at 2004-02-02 23:39
Message generated for change (Comment added) made by tjreedy
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=889500&group_id=5470

Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Jeff Connelly (jeffconnelly)
Assigned to: Nobody/Anonymous (nobody)
Summary: Line 0 SyntaxWarning with duplicate global declarations

Initial Comment:
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.



----------------------------------------------------------------------

Comment By: Terry J. Reedy (tjreedy)
Date: 2004-02-13 17:47

Message:
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 ;-)


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=889500&group_id=5470



More information about the Python-bugs-list mailing list