sphinx
sphinx copied to clipboard
Subclass methods do not display overloaded methods of the parent class
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.
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
related issue: https://github.com/Azure/autorest.python/issues/1315
Hi @tk0miya, could you please help on this?
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.