[Python-bugs-list] [ python-Bugs-577972 ] Scope trouble with __init__.py

noreply@sourceforge.net noreply@sourceforge.net
Fri, 05 Jul 2002 17:02:22 -0700


Bugs item #577972, was opened at 2002-07-05 18:02
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=577972&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Mike Romberg (romberg)
Assigned to: Nobody/Anonymous (nobody)
Summary: Scope trouble with __init__.py

Initial Comment:


  I think that there is a small problem with what gets
imported into the scope of an __init__.py module with
a package.  At least if this is the correct behavior it
seems a bit funny to me.

  Consider the following modules located in a subdirectory
of the load path called spam:

spam/
 
--------  spam/__init__.py ---------------
a = 1
from b import c
print "a = ", a


-------- spam/b.py -------------------
c = 2
import a

--------- spam/a.py -----------------
d = 3

  I would expect that when one imported the
spam package, you would see 'a = 1' displayed.
Instead you get 'a =  <module 'spam.a' from 'spam/a.py'>'.
So, it seems that python pulled in the 'a' symbol from b
and overwrote the one already in __init__.  This would
make sense if __init__ did a 'from b import *'.  But
I think the current behavior might be a bug.


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

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