[ python-Bugs-1053604 ] Unjustified SyntaxWarning

SourceForge.net noreply at sourceforge.net
Mon Oct 25 23:59:22 CEST 2004


Bugs item #1053604, was opened at 2004-10-25 05:06
Message generated for change (Comment added) made by jimjjewett
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1053604&group_id=5470

Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Markus Gritsch (markus_gritsch)
Assigned to: Nobody/Anonymous (nobody)
Summary: Unjustified SyntaxWarning

Initial Comment:
The following short script produces a "SyntaxWarning:
name 'cPickle' is assigned to before global
declaration", which is IMO not correct.


mode = 'pickle'

def main():
    if mode == 'pickle':
        global cPickle
        import cPickle
    elif mode == 'socket':
        global cPickle, socket
        import cPickle, socket
    elif mode == 'sqlite':
        global sqlite
        import sqlite
    else:
        print 'Warning: Unknown mode.'

def test():
    print cPickle.__doc__

if __name__ == '__main__':
    main()
    test()


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

Comment By: Jim Jewett (jimjjewett)
Date: 2004-10-25 17:59

Message:
Logged In: YES 
user_id=764593

The indenting was lost.  If I guess correctly, cPickle is 
global for modes pickle and socket, but not otherwise.

The problem is that it imports cpickle (for mode pickle) 
before running the global cpickle (for mode socket).

It would be nice if the interpreter were smart enough to 
realize that the paths are exclusive, but I'm inclined to call 
it a feature request rather than a bug.

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

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


More information about the Python-bugs-list mailing list