Skip to content
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

Closed
titanolodon mannequin opened this issue Apr 22, 2021 · 5 comments
Closed

An error in classmethod example in the documentation of descriptor #88083

titanolodon mannequin opened this issue Apr 22, 2021 · 5 comments
Assignees
Labels
3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@titanolodon
Copy link
Mannequin

titanolodon mannequin commented Apr 22, 2021

BPO 43917
Nosy @rhettinger, @miss-islington, @titanolodon
PRs
  • bpo-43917: Fix descriptor documentation example error #25541
  • bpo-43917: Fix pure python equivalent for classmethod #25544
  • [3.9] bpo-43917: Fix pure python equivalent for classmethod (GH-25544) #25546
  • 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:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2021-04-23.01:17:06.552>
    created_at = <Date 2021-04-22.22:46:38.093>
    labels = ['type-bug', '3.9', '3.10', 'docs']
    title = 'An error in classmethod example in the documentation of descriptor'
    updated_at = <Date 2021-04-23.01:17:06.548>
    user = 'https://github.com/titanolodon'

    bugs.python.org fields:

    activity = <Date 2021-04-23.01:17:06.548>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2021-04-23.01:17:06.552>
    closer = 'rhettinger'
    components = ['Documentation']
    creation = <Date 2021-04-22.22:46:38.093>
    creator = 'titanolodon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43917
    keywords = ['patch']
    message_count = 5.0
    messages = ['391638', '391639', '391644', '391646', '391647']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'docs@python', 'python-dev', 'miss-islington', 'titanolodon']
    pr_nums = ['25541', '25544', '25546']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43917'
    versions = ['Python 3.9', 'Python 3.10']

    @titanolodon
    Copy link
    Mannequin Author

    titanolodon mannequin commented Apr 22, 2021

    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 titanolodon mannequin assigned docspython Apr 22, 2021
    @titanolodon titanolodon mannequin added 3.9 only security fixes docs Documentation in the Doc dir labels Apr 22, 2021
    @titanolodon titanolodon mannequin assigned docspython Apr 22, 2021
    @titanolodon titanolodon mannequin added 3.9 only security fixes docs Documentation in the Doc dir labels Apr 22, 2021
    @rhettinger rhettinger assigned rhettinger and unassigned docspython Apr 22, 2021
    @rhettinger
    Copy link
    Contributor

    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);
    }

    @rhettinger
    Copy link
    Contributor

    New changeset 14092b5 by Raymond Hettinger in branch 'master':
    bpo-43917: Fix pure python equivalent for classmethod (GH-25544)
    14092b5

    @rhettinger
    Copy link
    Contributor

    New changeset 34be484 by Miss Islington (bot) in branch '3.9':
    bpo-43917: Fix pure python equivalent for classmethod (GH-25544) (GH-25546)
    34be484

    @rhettinger
    Copy link
    Contributor

    Okay, it's fixed. Thanks for the report.

    @rhettinger rhettinger added the 3.10 only security fixes label Apr 23, 2021
    @rhettinger rhettinger added type-bug An unexpected behavior, bug, or error 3.10 only security fixes labels Apr 23, 2021
    @rhettinger rhettinger added the type-bug An unexpected behavior, bug, or error label Apr 23, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant