Skip to content

util.inspect.getdoc doesn't accept a method decorated by a class with __get__ method #9756

@fbessou

Description

@fbessou

Describe the bug

When decorating a method with the python implementation of classmethod described here sphinx crashes complaining that the decorator has no attribute __func__

Here is a copy of the ClassMethod definition:

class ClassMethod:
    "Emulate PyClassMethod_Type() in Objects/funcobject.c"

    def __init__(self, f):
        self.f = f

    def __get__(self, obj, cls=None):
        if cls is None:
            cls = type(obj)
        if hasattr(type(self.f), '__get__'):
            return self.f.__get__(cls)
        return MethodType(self.f, cls)

How to Reproduce

$ git clone https://github.com/fbessou/sphinx-getitem
$ cd sphinx-getitem
$ pip install sphinx  # or use a virtualenv
$ cd doc
$ make html

The build crashes on the following error:

  File "<ENV>/lib/python3.7/site-packages/sphinx/util/inspect.py", line 853, in getdoc
    return getdoc(meth.__func__)
AttributeError: 'ClassMethod' object has no attribute '__func__'

Expected behavior

Sphinx shouldn't crash and the documented method should appear in the built documentation.

Your project

https://github.com/fbessou/sphinx-getitem

Screenshots

No response

OS

Linux (Debian Buster)

Python version

3.7

Sphinx version

4.2.0

Sphinx extensions

sphix.ext.autodoc

Extra tools

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions