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

Overridden classmethod documentation not inherited with autodoc #9757

Closed
EpicWink opened this issue Oct 21, 2021 · 5 comments
Closed

Overridden classmethod documentation not inherited with autodoc #9757

EpicWink opened this issue Oct 21, 2021 · 5 comments

Comments

@EpicWink
Copy link

EpicWink commented Oct 21, 2021

Describe the bug

The documentation for a classmethod in a parent class is not inherited by the method re-defined (without documentation) in a child class

How to Reproduce

Module src/spam.py:

class Parent:
    @classmethod
    def method(cls) -> int:
        """Return an integer."""
        return 17


class Child(Parent):
    @classmethod
    def method(cls):
        return 42

Sphinx configuration docs/conf.py:

project = "spam"
extensions = ["sphinx.ext.autodoc"]

Documentation index docs/index.rst:

spam
====

.. automodule:: spam
   :members:
   :undoc-members:

Build:

PYTHONPATH=src sphinx-build docs/ build

Expected behavior

Overridden classmethod to inherit documentation from parent class

Your project

https://github.com/EpicWink/python-swf-typed

Screenshots

Screenshot from 2021-10-21 20-13-39

OS

Ubuntu 20.04

Python version

3.8

Sphinx version

4.2.0

Sphinx extensions

sphinx.ext.autodoc

Additional context

inspect.getdoc(Child.method) returns the expected value

@tk0miya
Copy link
Member

tk0miya commented Oct 22, 2021

By default, autodoc searches the docstring from the parent class. Please disable autodoc_inherit_docstrings.
https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_inherit_docstrings

@EpicWink
Copy link
Author

Setting autodoc_inherit_docstrings = False didn't fix it. As a matter of fact, it (as the name suggests) disabled inheritance of docstrings for all methods, not just classmethods. Also, explicitly setting autodoc_inherit_docstrings = True didn't fix it

This to me seems like a bug specific to classmethods

@EpicWink
Copy link
Author

@tk0miya I don't think this issue is resolved

@tk0miya tk0miya reopened this Oct 29, 2021
@tk0miya
Copy link
Member

tk0miya commented Oct 29, 2021

Okay, I'll take a look.

@tk0miya
Copy link
Member

tk0miya commented Oct 29, 2021

Sorry, I misunderstand your report. Reproduced the error on my local.

@tk0miya tk0miya added this to the 4.3.0 milestone Oct 29, 2021
tk0miya added a commit that referenced this issue Oct 30, 2021
Fix #9757: autodoc_inherit_docstrings does not effect to overriden classmethods
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 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