3

Closed

__import__ and packages aren't mixing well

description

<Test>test_importpkg.py (test_import_globals)</Test>
<Area>import</Area>
 
File contents follow: note that doing "import y" instead of "import" changes the result.
 

test.py

import x.y
 

x/init.py

empty

 

x/y.py

a = 1
y = __import__('y')
print y.a
 

y.py

a = 2
 
 
The issue here is what we pass in in the default case. If you do:
 
y == __import__('y', globals(), locals())
 
then we both have the same behavior. But for just __import__('y') we still have enough information to figure out the calling module and do the import relative to that.
 
Fixing this involves changing our import code to look at the dictionary instead of our ICallerContext object. Because of the complexity of this change I'm moving this back to 1.1.
Closed Mar 4, 2008 at 12:08 AM by dfugate

comments

wrote Sep 8, 2006 at 6:39 PM

May be related to 2599

wrote Sep 14, 2007 at 11:12 PM

Might be fixed?

dfugate wrote Oct 4, 2007 at 6:44 PM

Still broken as of IronPython 2.0A5:

E:>type test.pyimport x.y

E:>type x__init__.py

E:>type x\y.pya = 1y = __import__('y')print "(x.y):", y.a

E:>type y.pya = 2

E:>cpy test.py(x.y): 2

E:>ipy test.py(x.y): 1