Skip to main content

sphinx-autodoc-typehints

This extension allows you to use Python 3 annotations for documenting acceptable argument types and return value types of functions. This allows you to use type hints in a very natural fashion, allowing you to migrate from this:

def format_unit(value, unit):
    """
    Formats the given value as a human readable string using the given units.

    :param float|int value: a numeric value
    :param str unit: the unit for the value (kg, m, etc.)
    :rtype: str
    """
    return '{} {}'.format(value, unit)

to this:

from typing import Union

def format_unit(value: Union[float, int], unit: str) -> str:
    """
    Formats the given value as a human readable string using the given units.

    :param value: a numeric value
    :param unit: the unit for the value (kg, m, etc.)
    """
    return '{} {}'.format(value, unit)

Installation and setup

First, use pip to download and install the extension:

$ pip install sphinx-autodoc-typehints

Then, add the extension to your conf.py:

extensions = [
    'sphinx.ext.autodoc',
    'sphinx_autodoc_typehints'
]

How it works

The extension listens to the autodoc-process-signature and autodoc-process-docstring Sphinx events. In the former, it strips the annotations from the function signature. In the latter, it injects the appropriate :type argname: and :rtype: directives into the docstring.

Only arguments that have an existing :param: directive in the docstring get their respective :type: directives added. The :rtype: directive is added if and only if no existing :rtype: is found.

This extension does not currently have any configuration options.

Metadata

Release files for sphinx-autodoc-typehints 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-autodoc-typehints 1.0.2
File Size Uploaded Provenance Actions
sphinx-autodoc-typehints-1.0.2.tar.gz 4.1 kB Without provenance Details for sphinx-autodoc-typehints-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-autodoc-typehints 1.0.2
File Interpreter ABI Platform Actions
sphinx_autodoc_typehints-1.0.2-py3-none-any.whl Python 3 none any Details for sphinx_autodoc_typehints-1.0.2-py3-none-any.whl

Total release size: 9.4 kB

Release files / sphinx-autodoc-typehints-1.0.2.tar.gz

Download URL sphinx-autodoc-typehints-1.0.2.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
335924e6b847063a639fa5fd27590aa4c1af08a9d20cf701183ba6c891d7f116
BLAKE2b-256 checksum
How to use checksums
c994295660e10108e47c1e1a3c6ac9e5fc85e87191a08efc7dfb2546321ac496
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / sphinx_autodoc_typehints-1.0.2-py3-none-any.whl

Download URL sphinx_autodoc_typehints-1.0.2-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e420e02d1c6850b5fc6803f5734fee790856023ea629e2cb167cf550640c7ff
BLAKE2b-256 checksum
How to use checksums
ae1ad287fbb64ef6d3930be8da36a629dad46fbe84886a163d5d2bb92140696b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for sphinx-autodoc-typehints 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page