Hi,

Recently, I've run across a bit of a bug while importing things with the
"from X import Y" syntax, when Y is anything but an an attribute of X
that already exists.

Demonstration:

IronPython 0.7.6 on .NET 2.0.50215.44
Copyright (c) Microsoft Corporation. All rights reserved.
 >>> from foo import bar
 >>> repr(bar)
'None'
 >>> from foo.bar import quux
 >>> repr(quux)
'<function quux at 0x00EA7F4A>'

One can work around the problem by doing a "regular" import first:

 >>> import foo.bar
 >>> from foo import bar
 >>> repr(bar)
'<module foo.bar from "C:\\Documents and
Settings\\JJ\\Desktop\\IronPython-0.7.6-orig\\bin\\foo\\bar.py">'

After doing some digging I've come up with a solution. Even though I
don't really think it is a clean solution, I've attached the patch anyway.

--
Jonathan

diff -ru IronPython-0.7.6-orig/IronPython/Objects/Ops.cs 
IronPython-0.7.6/IronPython/Objects/Ops.cs
--- IronPython-0.7.6-orig/IronPython/Objects/Ops.cs     Sun Jun 12 17:01:42 2005
+++ IronPython-0.7.6/IronPython/Objects/Ops.cs  Tue Jul  5 16:17:30 2005
@@ -2103,6 +2103,10 @@
 
                 try {
                     impObj = Importer.GetFrom(fromObj, names[i]);
+                    if (impObj == null) {
+                        Ops.ImportAs(mod, fullName + "." + names[i], 
asNames[i] != null ? asNames[i] : names[i]);
+                        continue;
+                    }
                 } catch {
                     throw ImportError("Cannot import {0} from {1}", names[i], 
fromObj);
                 }

_______________________________________________
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to