Author: Carl Friedrich Bolz <[email protected]>
Branch: py3.5
Changeset: r88750:10fde59504a2
Date: 2016-11-29 17:32 +0100
http://bitbucket.org/pypy/pypy/changeset/10fde59504a2/

Log:    only Exceptions (not BaseExceptions) are ignored when calling
        module_repr

diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -125,8 +125,9 @@
         if w_loader is not None:
             try:
                 return space.call_method(w_loader, "module_repr", self)
-            except OperationError:
-                pass
+            except OperationError, operr:
+                if not operr.match(space, space.w_Exception):
+                    raise
         try:
             w_name = space.getattr(self, space.wrap('__name__'))
             name = space.unicode_w(space.repr(w_name))
diff --git a/pypy/interpreter/test/test_module.py 
b/pypy/interpreter/test/test_module.py
--- a/pypy/interpreter/test/test_module.py
+++ b/pypy/interpreter/test/test_module.py
@@ -129,6 +129,20 @@
         expected_repr = "<module 'test_module' ({})>".format(loader_repr)
         assert mod_repr == expected_repr
 
+    def test_repr_with_loader_with_raising_module_repr2(self):
+        import sys
+        test_module = type(sys)("test_module", "doc")
+        # If an exception occurs in module_repr(), the exception is caught
+        # and discarded, and the calculation of the module&#8217;s repr 
continues
+        # as if module_repr() did not exist.
+        class CustomLoaderWithRaisingRepr:
+            @classmethod
+            def module_repr(cls, module):
+                raise KeyboardInterrupt
+
+        test_module.__loader__ = CustomLoaderWithRaisingRepr
+        raises(KeyboardInterrupt, 'repr(test_module)')
+
     def test_repr_with_raising_loader_and___file__(self):
         import sys
         test_module = type(sys)("test_module", "doc")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to