Render Python type hints in Sphinx autodoc documentation
Actively maintained. Last release 7 days ago, commits in 26 of the last 26 weeks. A safe choice.
pip install sphinx-autodoc-typehintssphinx-autodoc-typehints
This Sphinx extension reads the
type hints of the code autodoc documents and writes them into the
parameter and return fields, so you state each type once, in the code. It links every part of a type to its
documentation, and resolves names your code imports only for type checkers (inside an if TYPE_CHECKING: block) or
declares in .pyi stub files. It also documents @overload variants and default values, and types Google and NumPy
style docstrings written for napoleon or numpydoc.
pip install sphinx-autodoc-typehints
# conf.py: load autodoc first, then this extension
extensions = ["sphinx.ext.autodoc", "sphinx_autodoc_typehints"]
Why not Sphinx's built-in autodoc_typehints?
Sphinx's already moves annotations into the parameter and return fields, links them, and works with napoleon docstrings and type comments. If your annotations resolve at runtime and you use Sphinx fields or napoleon, that setting may be enough.
