[Jython-checkins] jython: Expose reload in imp module to make test_imp happy.

frank.wierzbicki jython-checkins at python.org
Fri Mar 23 18:31:13 CET 2012


http://hg.python.org/jython/rev/fc60040abea4
changeset:   6492:fc60040abea4
user:        Frank Wierzbicki <fwierzbicki at gmail.com>
date:        Fri Mar 23 10:31:04 2012 -0700
summary:
  Expose reload in imp module to make test_imp happy.

files:
  src/org/python/core/__builtin__.java |  26 +++++++++------
  src/org/python/modules/imp.java      |   5 +++
  2 files changed, 20 insertions(+), 11 deletions(-)


diff --git a/src/org/python/core/__builtin__.java b/src/org/python/core/__builtin__.java
--- a/src/org/python/core/__builtin__.java
+++ b/src/org/python/core/__builtin__.java
@@ -104,17 +104,7 @@
             case 34:
                 return Py.newString(__builtin__.raw_input(arg1));
             case 36:
-                Object o = arg1.__tojava__(PyModule.class);
-                if (o == Py.NoConversion) {
-                    if (arg1 instanceof PySystemState) {
-                        return __builtin__.reload((PySystemState)arg1);
-                    } else if(arg1 instanceof PyJavaType) {
-                        // This has always been a no-op.  Should be disabled in py3k.
-                        return arg1;
-                    }
-                    throw Py.TypeError("reload() argument must be a module");
-                }
-                return __builtin__.reload((PyModule) o);
+                return __builtin__.reload(arg1);
             case 37:
                 return __builtin__.repr(arg1);
             case 41:
@@ -1043,6 +1033,20 @@
         return reduce(f, l, null);
     }
 
+    public static PyObject reload(PyObject o) {
+        Object module = o.__tojava__(PyModule.class);
+        if (module == Py.NoConversion) {
+            if (o instanceof PySystemState) {
+                return __builtin__.reload((PySystemState)o);
+            } else if(o instanceof PyJavaType) {
+                // This has always been a no-op.  Should be disabled in py3k.
+                return o;
+            }
+            throw Py.TypeError("reload() argument must be a module");
+        }
+        return __builtin__.reload((PyModule) module);
+    }
+
     public static PyObject reload(PyModule o) {
         return imp.reload(o);
     }
diff --git a/src/org/python/modules/imp.java b/src/org/python/modules/imp.java
--- a/src/org/python/modules/imp.java
+++ b/src/org/python/modules/imp.java
@@ -1,6 +1,7 @@
 
 package org.python.modules;
 
+import org.python.core.__builtin__;
 import org.python.core.Py;
 import org.python.core.PyFile;
 import org.python.core.PyList;
@@ -163,6 +164,10 @@
         return load_compiled(name, pathname, new PyFile(pathname, "rb", -1));
     }
 
+    public static PyObject reload(PyObject module) {
+        return __builtin__.reload(module);
+    }
+
     public static PyObject load_compiled(String name, String pathname, PyObject file) {
         InputStream stream = (InputStream) file.__tojava__(InputStream.class);
         if (stream == Py.NoConversion) {

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list