Commit 871309c7 authored by Inada Naoki's avatar Inada Naoki Committed by Miss Islington (bot)

bpo-36433: fix confusing error messages in classmethoddescr_call (GH-12556)



https://bugs.python.org/issue36433
parent b4d8f28a
...@@ -1597,12 +1597,27 @@ order (MRO) for bases """ ...@@ -1597,12 +1597,27 @@ order (MRO) for bases """
self.assertEqual(x2, SubSpam) self.assertEqual(x2, SubSpam)
self.assertEqual(a2, a1) self.assertEqual(a2, a1)
self.assertEqual(d2, d1) self.assertEqual(d2, d1)
with self.assertRaises(TypeError):
with self.assertRaises(TypeError) as cm:
spam_cm() spam_cm()
with self.assertRaises(TypeError): self.assertEqual(
str(cm.exception),
"descriptor 'classmeth' of 'xxsubtype.spamlist' "
"object needs an argument")
with self.assertRaises(TypeError) as cm:
spam_cm(spam.spamlist()) spam_cm(spam.spamlist())
with self.assertRaises(TypeError): self.assertEqual(
str(cm.exception),
"descriptor 'classmeth' requires a type "
"but received a 'xxsubtype.spamlist' instance")
with self.assertRaises(TypeError) as cm:
spam_cm(list) spam_cm(list)
self.assertEqual(
str(cm.exception),
"descriptor 'classmeth' requires a subtype of 'xxsubtype.spamlist' "
"but received 'list'")
def test_staticmethods(self): def test_staticmethods(self):
# Testing static methods... # Testing static methods...
......
...@@ -315,20 +315,18 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, ...@@ -315,20 +315,18 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
if (!PyType_Check(self)) { if (!PyType_Check(self)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"descriptor '%V' requires a type " "descriptor '%V' requires a type "
"but received a '%.100s'", "but received a '%.100s' instance",
descr_name((PyDescrObject *)descr), "?", descr_name((PyDescrObject *)descr), "?",
PyDescr_TYPE(descr)->tp_name,
self->ob_type->tp_name); self->ob_type->tp_name);
return NULL; return NULL;
} }
if (!PyType_IsSubtype((PyTypeObject *)self, PyDescr_TYPE(descr))) { if (!PyType_IsSubtype((PyTypeObject *)self, PyDescr_TYPE(descr))) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"descriptor '%V' " "descriptor '%V' requires a subtype of '%.100s' "
"requires a subtype of '%.100s' " "but received '%.100s'",
"but received '%.100s",
descr_name((PyDescrObject *)descr), "?", descr_name((PyDescrObject *)descr), "?",
PyDescr_TYPE(descr)->tp_name, PyDescr_TYPE(descr)->tp_name,
self->ob_type->tp_name); ((PyTypeObject*)self)->tp_name);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment