diff -r ed8eefa6d57c Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Mon Mar 21 08:55:16 2011 +0100 +++ b/Lib/test/test_exceptions.py Tue Mar 22 02:20:43 2011 +0100 @@ -708,6 +708,16 @@ self.fail("RuntimeError not raised") self.assertEqual(wr(), None) + def test_new_returns_invalid_instance(self): + # See issue #11627. + class MyException(Exception): + def __new__(cls, *args): + return object() + + def raise_(): + raise MyException + self.assertRaises(TypeError, raise_) + def test_main(): run_unittest(ExceptionTests) diff -r ed8eefa6d57c Python/ceval.c --- a/Python/ceval.c Mon Mar 21 08:55:16 2011 +0100 +++ b/Python/ceval.c Tue Mar 22 02:20:43 2011 +0100 @@ -3249,6 +3249,13 @@ value = PyObject_CallObject(exc, NULL); if (value == NULL) goto raise_error; + else if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto raise_error; + } } else if (PyExceptionInstance_Check(exc)) { value = exc;