diff options
author | Inada Naoki <songofacandy@gmail.com> | 2019-03-26 18:26:33 +0900 |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-03-26 02:26:33 -0700 |
commit | 871309c775fd4d72048bfaa31affd54f9934f7dd (patch) | |
tree | 74a8d1910e61d82b91bf5a0d16de147a6f5a5588 | |
parent | b4d8f28a8af4f35c951c13a5c29630d1fb401105 (diff) | |
download | cpython-git-871309c775fd4d72048bfaa31affd54f9934f7dd.tar.gz |
bpo-36433: fix confusing error messages in classmethoddescr_call (GH-12556)
https://bugs.python.org/issue36433
-rw-r--r-- | Lib/test/test_descr.py | 21 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2019-03-26-17-23-02.bpo-36433.-8XzZf.rst | 1 | ||||
-rw-r--r-- | Objects/descrobject.c | 10 |
3 files changed, 23 insertions, 9 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index e39fea615d..09eef8c56f 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1597,12 +1597,27 @@ order (MRO) for bases """ 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... diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-03-26-17-23-02.bpo-36433.-8XzZf.rst b/Misc/NEWS.d/next/Core and Builtins/2019-03-26-17-23-02.bpo-36433.-8XzZf.rst new file mode 100644 index 0000000000..6d1bd288bd --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-03-26-17-23-02.bpo-36433.-8XzZf.rst @@ -0,0 +1 @@ +Fixed TypeError message in classmethoddescr_call. diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 22546a563a..ab4151ec93 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -315,20 +315,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; } |