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 3, 2008 at 11:08 PM by dfugate

comments

wrote Sep 8, 2006 at 5:39 PM

May be related to 2599

wrote Sep 11, 2006 at 9:22 PM

wrote Sep 27, 2006 at 3:54 PM

wrote Jan 23, 2007 at 7:01 AM

wrote Feb 23, 2007 at 6:47 PM

wrote Mar 29, 2007 at 12:49 PM

wrote May 20, 2007 at 7:23 PM

wrote Jun 4, 2007 at 11:57 PM

wrote Jul 26, 2007 at 4:33 PM

wrote Sep 12, 2007 at 8:53 PM

wrote Sep 14, 2007 at 10:12 PM

Might be fixed?

wrote Sep 19, 2007 at 4:27 PM

dfugate wrote Oct 4, 2007 at 5: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

wrote Oct 4, 2007 at 5:45 PM

wrote Feb 27, 2008 at 9:59 PM

wrote Feb 28, 2008 at 11:02 PM

wrote Mar 3, 2008 at 11:08 PM

wrote Mar 3, 2008 at 11:08 PM

wrote Apr 18, 2008 at 10:37 PM

wrote Feb 22, 2013 at 1:17 AM

wrote May 16, 2013 at 12:07 PM