sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.55k stars 2.12k forks source link

Subclass methods do not display overloaded methods of the parent class #10635

Open BigCat20196 opened 2 years ago

BigCat20196 commented 2 years ago

Describe the bug

Hi Team, when we use Sphinx to render documents, we encounter a scene where we need to list the overloaded methods of the parent class in the subclass, but we still can't get the desired results.

The following codes are assumptions.

from typing import overload

class Father:

    @overload
    def father_func(self, para: int):
        ...

    @overload
    def father_func(self, para: str):
        ...

    def father_func(self, *args):
        ...

class Son(Father):
    @overload
    def son_func(self):
        ...

    def son_func(self, para: str):
        ...

The bar class inherits from the foo class, but the overloaded methods of the parent class are not displayed in the rendered document. image

How to Reproduce

$ mkdir demo
# Create a py file, copy and paste the above code
$ cd ..\docs
$ $env:SPHINX_APIDOC_OPTIONS="members,undoc-members,inherited-members"
$ sphinx-apidoc -f -o . ..\demo
$ sphinx-build -b html . _build

Expected behavior

It can show the overloaded methods of the parent class in the subclass

Your project

None

Screenshots

No response

OS

win10

Python version

python 3.8.2

Sphinx version

5.0.0

Sphinx extensions

['sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinx.ext.doctest', 'sphinx.ext.viewcode', 'sphinx.ext.intersphinx', 'sphinx.ext.napoleon', 'sphinx_toolbox.more_autodoc.overloads']

Extra tools

No response

Additional context

No response

msyyc commented 2 years ago

related issue: https://github.com/Azure/autorest.python/issues/1315

BigCat20196 commented 2 years ago

Hi @tk0miya, could you please help on this?

ntessore commented 1 year ago

I wrote a small extension sphinxcontrib.autodoc_inherit_overload that works around this issue by manually resolving the overloads using typing.get_overloads(). As such, it requires Python 3.11.