diff -r 3aec82018a18 Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Tue Mar 22 09:11:39 2011 -0700 +++ b/Lib/test/test_exceptions.py Tue Mar 22 23:38:53 2011 +0100 @@ -708,6 +708,15 @@ 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() + + with self.assertRaises(TypeError): + raise MyException + def test_main(): run_unittest(ExceptionTests) diff -r 3aec82018a18 Python/ceval.c --- a/Python/ceval.c Tue Mar 22 09:11:39 2011 -0700 +++ b/Python/ceval.c Tue Mar 22 23:38:53 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;