This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: An error in classmethod example in the documentation of descriptor
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.10, Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: docs@python, miss-islington, python-dev, rhettinger, titanolodon
Priority: normal Keywords: patch

Created on 2021-04-22 22:46 by titanolodon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25541 closed python-dev, 2021-04-22 23:03
PR 25544 merged rhettinger, 2021-04-22 23:37
PR 25546 merged miss-islington, 2021-04-23 00:53
Messages (5)
msg391638 - (view) Author: Egor (titanolodon) * Date: 2021-04-22 22:46
In this section 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__").
msg391639 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-04-22 23:20
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) {
                        "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,
    return PyMethod_New(cm->cm_callable, type);
msg391644 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-04-23 00:53
New changeset 14092b5a4ae4caf1c77f685450016a0d1ad0bd6c by Raymond Hettinger in branch 'master':
bpo-43917: Fix pure python equivalent for classmethod (GH-25544)
msg391646 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-04-23 01:16
New changeset 34be48450f03b121be10a9f8e8989603478f0469 by Miss Islington (bot) in branch '3.9':
bpo-43917: Fix pure python equivalent for classmethod (GH-25544) (GH-25546)
msg391647 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-04-23 01:17
Okay, it's fixed.  Thanks for the report.
Date User Action Args
2022-04-11 14:59:44adminsetgithub: 88083
2021-04-23 01:17:06rhettingersetstatus: open -> closed
versions: + Python 3.10
type: behavior
messages: + msg391647

resolution: fixed
stage: patch review -> resolved
2021-04-23 01:16:23rhettingersetmessages: + msg391646
2021-04-23 00:53:45miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request24270
2021-04-23 00:53:44rhettingersetmessages: + msg391644
2021-04-22 23:37:42rhettingersetpull_requests: + pull_request24268
2021-04-22 23:20:24rhettingersetmessages: + msg391639
2021-04-22 23:03:18python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request24262
stage: patch review
2021-04-22 23:01:12rhettingersetassignee: docs@python -> rhettinger
2021-04-22 22:46:38titanolodoncreate