diff -r 7ce459fc57b9 Lib/test/test_py3kwarn.py --- a/Lib/test/test_py3kwarn.py Thu Oct 02 11:36:01 2014 +0300 +++ b/Lib/test/test_py3kwarn.py Thu Oct 02 20:33:10 2014 +0300 @@ -259,6 +259,14 @@ class TestPy3KWarnings(unittest.TestCase self.assertWarning(None, w, "Overriding __eq__ blocks inheritance of __hash__ in 3.x") w.reset() + with warnings.catch_warnings(): + warnings.filterwarnings("error") + with self.assertRaisesRegexp(DeprecationWarning, + "Overriding __eq__ blocks inheritance of __hash__ in 3.x"): + class WarnOnlyEq(object): + def __eq__(self, other): pass + self.assertEqual(len(w.warnings), 0) + w.reset() class WarnCmpAndEq(object): def __cmp__(self, other): pass def __eq__(self, other): pass diff -r 7ce459fc57b9 Objects/typeobject.c --- a/Objects/typeobject.c Thu Oct 02 11:36:01 2014 +0300 +++ b/Objects/typeobject.c Thu Oct 02 20:33:10 2014 +0300 @@ -3769,7 +3769,7 @@ overrides_name(PyTypeObject *type, char #define OVERRIDES_HASH(x) overrides_name(x, "__hash__") #define OVERRIDES_EQ(x) overrides_name(x, "__eq__") -static void +static int inherit_slots(PyTypeObject *type, PyTypeObject *base) { PyTypeObject *basebase; @@ -3917,12 +3917,7 @@ inherit_slots(PyTypeObject *type, PyType "__eq__ blocks inheritance " "of __hash__ in 3.x", 1) < 0) - /* XXX This isn't right. If the warning is turned - into an exception, we should be communicating - the error back to the caller, but figuring out - how to clean up in that case is tricky. See - issue 8627 for more. */ - PyErr_Clear(); + return -1; } } } @@ -3961,6 +3956,7 @@ inherit_slots(PyTypeObject *type, PyType * obvious to be done -- the type is on its own. */ } + return 0; } static int add_operators(PyTypeObject *); @@ -4070,7 +4066,8 @@ PyType_Ready(PyTypeObject *type) for (i = 1; i < n; i++) { PyObject *b = PyTuple_GET_ITEM(bases, i); if (PyType_Check(b)) - inherit_slots(type, (PyTypeObject *)b); + if (inherit_slots(type, (PyTypeObject *)b) < 0) + goto error; } /* Sanity check for tp_free. */