Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: 
Changeset: r97805:f27546b858f9
Date: 2019-10-17 23:22 +0200
http://bitbucket.org/pypy/pypy/changeset/f27546b858f9/

Log:    issue #3099: allow reloading of subclasses of module

diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -723,7 +723,7 @@
 def reload(space, w_module):
     """Reload the module.
     The module must have been successfully imported before."""
-    if not space.is_w(space.type(w_module), space.type(space.sys)):
+    if not space.isinstance_w(w_module, space.type(space.sys)):
         raise oefmt(space.w_TypeError, "reload() argument must be module")
 
     w_modulename = space.getattr(w_module, space.newtext("__name__"))
diff --git a/pypy/module/imp/test/test_import.py 
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -656,6 +656,20 @@
     def test_reload_infinite(self):
         import infinite_reload
 
+    def test_reload_module_subclass(self):
+        import types
+
+        #MyModType = types.ModuleType
+        class MyModType(types.ModuleType):
+            pass
+
+        m = MyModType("abc")
+        with raises(ImportError):
+            # Fails because the module is not in sys.modules, but *not* because
+            # it's a subtype of ModuleType.
+            reload(m)
+
+
     def test_explicitly_missing(self):
         import sys
         sys.modules['foobarbazmod'] = None
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to