[Jython-checkins] jython (merge 2.5 -> default): merge with 2.5
philip.jenvey
jython-checkins at python.org
Tue Oct 25 02:17:39 CEST 2011
http://hg.python.org/jython/rev/2a60a68ed086
changeset: 6255:2a60a68ed086
parent: 6253:704b07c1d5f5
parent: 6254:4c672dbbcdb2
user: Philip Jenvey <pjenvey at underboss.org>
date: Mon Oct 24 17:17:01 2011 -0700
summary:
merge with 2.5
files:
Lib/test/issue1811/__init__.py | Bin
Lib/test/issue1811/foo.py | 1 +
Lib/test/test_import_jy.py | 6 ++
src/org/python/core/PyModule.java | 8 ---
src/org/python/core/imp.java | 43 ++++++++++++++---
5 files changed, 41 insertions(+), 17 deletions(-)
diff --git a/Lib/test/issue1811/__init__.py b/Lib/test/issue1811/__init__.py
new file mode 100644
diff --git a/Lib/test/issue1811/foo.py b/Lib/test/issue1811/foo.py
new file mode 100644
--- /dev/null
+++ b/Lib/test/issue1811/foo.py
@@ -0,0 +1,1 @@
+issue1811 = __import__('test.issue1811', globals(), locals(), ['foo'])
diff --git a/Lib/test/test_import_jy.py b/Lib/test/test_import_jy.py
--- a/Lib/test/test_import_jy.py
+++ b/Lib/test/test_import_jy.py
@@ -205,6 +205,12 @@
shutil.rmtree(test_support.TESTFN)
test_support.unlink(sym)
+ def test_issue1811(self):
+ # Previously this blew out the stack
+ from test.issue1811 import foo
+ self.assertTrue(foo.issue1811.foo is foo)
+
+
def test_main():
test_support.run_unittest(MislabeledImportTestCase,
OverrideBuiltinsImportTestCase,
diff --git a/src/org/python/core/PyModule.java b/src/org/python/core/PyModule.java
--- a/src/org/python/core/PyModule.java
+++ b/src/org/python/core/PyModule.java
@@ -119,14 +119,6 @@
return null;
}
- @Override
- public PyObject __findattr_ex__(String name) {
- PyObject attr=super.__findattr_ex__(name);
- if (attr!=null)
- return attr;
- return impAttr(name);
- }
-
public void __setattr__(String name, PyObject value) {
module___setattr__(name, value);
}
diff --git a/src/org/python/core/imp.java b/src/org/python/core/imp.java
--- a/src/org/python/core/imp.java
+++ b/src/org/python/core/imp.java
@@ -846,19 +846,44 @@
}
if (fromlist != null && fromlist != Py.None) {
- StringBuilder modNameBuffer = new StringBuilder(name);
- for (PyObject submodName : fromlist.asIterable()) {
- if (mod.__findattr__(submodName.toString()) != null
- || submodName.toString().equals("*")) {
- continue;
- }
- String fullName = modNameBuffer.toString() + "." + submodName.toString();
- import_next(mod, modNameBuffer, submodName.toString(), fullName, null);
- }
+ ensureFromList(mod, fromlist, name);
}
return mod;
}
+ private static void ensureFromList(PyObject mod, PyObject fromlist, String name) {
+ ensureFromList(mod, fromlist, name, false);
+ }
+
+ private static void ensureFromList(PyObject mod, PyObject fromlist, String name,
+ boolean recursive) {
+ if (mod.__findattr__("__path__") == null) {
+ return;
+ }
+
+ StringBuilder modNameBuffer = new StringBuilder(name);
+ for (PyObject item : fromlist.asIterable()) {
+ if (!Py.isInstance(item, PyString.TYPE)) {
+ throw Py.TypeError("Item in ``from list'' not a string");
+ }
+ if (item.toString().equals("*")) {
+ if (recursive) {
+ // Avoid endless recursion
+ continue;
+ }
+ PyObject all;
+ if ((all = mod.__findattr__("__all__")) != null) {
+ ensureFromList(mod, all, name, true);
+ }
+ }
+
+ if (mod.__findattr__((PyString) item) == null) {
+ String fullName = modNameBuffer.toString() + "." + item.toString();
+ import_next(mod, modNameBuffer, item.toString(), fullName, null);
+ }
+ }
+ }
+
/**
* Import a module by name.
*
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list