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
An error in classmethod example in the documentation of descriptor #88083
Comments
In this section https://docs.python.org/3/howto/descriptor.html#class-methods in the example of python implementation of ClassMethod inside __get__ method I think that we should check hasattr(self.f, "__get__") instead of hasattr(obj, "__get__"). |
titanolodon
mannequin
added
3.9
only security fixes
docs
Documentation in the Doc dir
labels
Apr 22, 2021
titanolodon
mannequin
added
3.9
only security fixes
docs
Documentation in the Doc dir
labels
Apr 22, 2021
It looks like it should be: if hasattr(type(self.f), "__get__"): Here's the relevant C code: static PyObject *
cm_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
classmethod *cm = (classmethod *)self;
if (cm->cm_callable == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"uninitialized classmethod object");
return NULL;
}
if (type == NULL)
type = (PyObject *)(Py_TYPE(obj));
if (Py_TYPE(cm->cm_callable)->tp_descr_get != NULL) {
return Py_TYPE(cm->cm_callable)->tp_descr_get(cm->cm_callable, type,
NULL);
}
return PyMethod_New(cm->cm_callable, type);
} |
Okay, it's fixed. Thanks for the report. |
rhettinger
added
type-bug
An unexpected behavior, bug, or error
3.10
only security fixes
labels
Apr 23, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: