-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-36433: fix confusing error messages in classmethoddescr_call #12556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Objects/descrobject.c
Outdated
@@ -314,21 +314,20 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, | |||
self = PyTuple_GET_ITEM(args, 0); | |||
if (!PyType_Check(self)) { | |||
PyErr_Format(PyExc_TypeError, | |||
"descriptor '%V' requires a type " | |||
"but received a '%.100s'", | |||
"descriptor '%V' requires a subtype of '%.100s' " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that subtype of '%.100s'
is better than just type
. It contains more information, but I think that this information is redundant at that moment and distracts from the true error -- passing an instance instead of a type.
Maybe just remove PyDescr_TYPE(descr)->tp_name
?
Lib/test/test_descr.py
Outdated
spam_cm() | ||
with self.assertRaises(TypeError): | ||
self.assertEqual( | ||
cm.exception.args[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be better to test str(cm.exception)
instead of cm.exception.args[0]
. Just for the case if error messages be generated dynamically in the future.
@methane: Status check is done, and it's a success ✅ . |
Thanks @methane for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
GH-12557 is a backport of this pull request to the 3.7 branch. |
…honGH-12556) https://bugs.python.org/issue36433 (cherry picked from commit 871309c) Co-authored-by: Inada Naoki <songofacandy@gmail.com>
…12556) https://bugs.python.org/issue36433 (cherry picked from commit 871309c) Co-authored-by: Inada Naoki <songofacandy@gmail.com>
https://bugs.python.org/issue36433