Skip to content

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

Merged
merged 4 commits into from
Mar 26, 2019

Conversation

methane
Copy link
Member

@methane methane commented Mar 26, 2019

@@ -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' "
Copy link
Member

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?

spam_cm()
with self.assertRaises(TypeError):
self.assertEqual(
cm.exception.args[0],
Copy link
Member

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.

@miss-islington
Copy link
Contributor

@methane: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit 871309c into python:master Mar 26, 2019
@miss-islington
Copy link
Contributor

Thanks @methane for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-12557 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 26, 2019
miss-islington added a commit that referenced this pull request Mar 26, 2019
…12556)

https://bugs.python.org/issue36433
(cherry picked from commit 871309c)

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
@methane methane deleted the classmethod_descr branch April 28, 2025 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants