catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)
Patch from Andreas Stührk.
diff --git a/Lib/test/test_raise.py b/Lib/test/test_raise.py
index d120dc1..e02c1af 100644
--- a/Lib/test/test_raise.py
+++ b/Lib/test/test_raise.py
@@ -121,6 +121,15 @@
else:
self.fail("No exception raised")
+ def test_new_returns_invalid_instance(self):
+ # See issue #11627.
+ class MyException(Exception):
+ def __new__(cls, *args):
+ return object()
+
+ with self.assertRaises(TypeError):
+ raise MyException
+
class TestCause(unittest.TestCase):
def test_invalid_cause(self):