Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,12 +1592,27 @@ class SubSpam(spam.spamlist): pass
self.assertEqual(x2, SubSpam)
self.assertEqual(a2, a1)
self.assertEqual(d2, d1)
with self.assertRaises(TypeError):

with self.assertRaises(TypeError) as 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())
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)
self.assertEqual(
str(cm.exception),
"descriptor 'classmeth' requires a subtype of 'xxsubtype.spamlist' "
"but received 'list'")

def test_staticmethods(self):
# Testing static methods...
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed TypeError message in classmethoddescr_call.
10 changes: 4 additions & 6 deletions Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,18 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
if (!PyType_Check(self)) {
PyErr_Format(PyExc_TypeError,
"descriptor '%V' requires a type "
"but received a '%.100s'",
"but received a '%.100s' instance",
descr_name((PyDescrObject *)descr), "?",
PyDescr_TYPE(descr)->tp_name,
self->ob_type->tp_name);
return NULL;
}
if (!PyType_IsSubtype((PyTypeObject *)self, PyDescr_TYPE(descr))) {
PyErr_Format(PyExc_TypeError,
"descriptor '%V' "
"requires a subtype of '%.100s' "
"but received '%.100s",
"descriptor '%V' requires a subtype of '%.100s' "
"but received '%.100s'",
descr_name((PyDescrObject *)descr), "?",
PyDescr_TYPE(descr)->tp_name,
self->ob_type->tp_name);
((PyTypeObject*)self)->tp_name);
return NULL;
}

Expand Down