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

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

Closed
fbessou opened this issue Oct 21, 2021 · 0 comments

Comments

@fbessou
Copy link

fbessou commented Oct 21, 2021

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

@tk0miya tk0miya added this to the 4.3.0 milestone Oct 22, 2021
tk0miya added a commit that referenced this issue Oct 26, 2021
Fix #9756: autodoc: Crashed if classmethod does not have __func__ attribute
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants