Skip to content

Comments

✨ feat(annotations): support Annotated with Doc() for param descriptions#631

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:feat/149-annotated-doc
Feb 25, 2026
Merged

✨ feat(annotations): support Annotated with Doc() for param descriptions#631
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:feat/149-annotated-doc

Conversation

@gaborbernat
Copy link
Member

Functions using Annotated[type, Doc("description")] (PEP 727 / typing_extensions.Doc) encode parameter documentation directly in type annotations. The extension already preserves Annotated wrappers via include_extras=True in get_type_hints(), but immediately discards the metadata when formatting — so users who document parameters via Doc() get no descriptions in their Sphinx output unless they duplicate them in docstrings.

✨ This extracts Doc() descriptions from Annotated metadata and injects them as :param: and :return: fields when the docstring doesn't already document that parameter. Existing docstring entries always take precedence over Doc() descriptions. The type is still unwrapped from Annotated as before for :type: rendering. Detection uses duck-typing on the Doc class identity (module + qualname) to avoid a hard dependency on typing_extensions.

Both Sphinx field list and numpydoc formats are supported — numpydoc converts to Sphinx field list syntax before injection runs, so the Doc logic works for both without format-specific code.

Closes #149

Functions using Annotated[type, Doc("description")] (PEP 727) encode
parameter documentation directly in type annotations, but the extension
discarded this metadata when formatting. Users had to duplicate
descriptions in docstrings to get any output.

Extract Doc() descriptions and inject them as :param: and :return:
fields when the docstring doesn't already document that parameter.
Existing docstring entries always take precedence. Works with both
Sphinx field list and numpydoc formats since numpydoc converts to
field lists before injection runs.
@gaborbernat gaborbernat force-pushed the feat/149-annotated-doc branch from a58782b to bf00802 Compare February 24, 2026 18:46
@gaborbernat gaborbernat merged commit 49acfd6 into tox-dev:main Feb 25, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support pep 593 typing.Annotated to avoid repeating :param {arg}: for each arg

1 participant