sphinx-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:

# conf.py: load autodoc first, then this extension
extensions = ["sphinx.ext.autodoc", "sphinx_autodoc_typehints"]

Sphinx’s own autodoc_typehints = "description" also moves types into the fields. This extension links names your code imports only for type checkers, inside an if TYPE_CHECKING: block, and reads types from .pyi stub files, which hold the annotations of a module whose code has none. It documents the @overload variants a function declares for type checkers, default values, the keys of **kwargs, and docstrings written for numpydoc. Compared with Sphinx’s built-in type hints lists the differences, and the Changelog lists the changes in each version.

Installation

sphinx-autodoc-typehints is available on PyPI. It needs Python 3.12 or later and Sphinx 9.1 or later:

python -m pip install sphinx-autodoc-typehints

Parallel builds, sphinx-build -j, work with the extension loaded.

Learn sphinx-autodoc-typehints

New to the extension?

Start with the Tutorials to document a first annotated module.

Have a specific task?

Each of the How-to guides changes one thing about the output, such as where types appear or how defaults show.

Looking up an option?

The Reference lists the configuration options, the warnings and how each typing construct renders.

Exploring a typing feature?

The Typing features gallery gallery shows the source and rendered output for each construct, alongside Sphinx’s output.

Want to know how it works?

How it works follows a type from the annotation to the rendered page.

Features

Types in the fields

Parameter and return types go below the signature, or stay in it.

Every docstring style

Sphinx’s :param: fields, Google or NumPy sections through napoleon, or numpydoc’s sections.

Types that resolve

A name imported only for type checkers, or declared in a .pyi stub, links like any other.

Linked types

Every part of a type links to its documentation, type aliases included.

Overloads and kwargs

Each @overload variant, and each keyword argument a TypedDict types.

Objects beyond functions

Notices for deprecated objects, links to overridden methods, and the types of attributes and setters.