✨ feat(annotations): support Annotated with Doc() for param descriptions#631
Merged
gaborbernat merged 1 commit intotox-dev:mainfrom Feb 25, 2026
Merged
Conversation
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.
a58782b to
bf00802
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Functions using
Annotated[type, Doc("description")](PEP 727 /typing_extensions.Doc) encode parameter documentation directly in type annotations. The extension already preservesAnnotatedwrappers viainclude_extras=Trueinget_type_hints(), but immediately discards the metadata when formatting — so users who document parameters viaDoc()get no descriptions in their Sphinx output unless they duplicate them in docstrings.✨ This extracts
Doc()descriptions fromAnnotatedmetadata and injects them as:param:and:return:fields when the docstring doesn't already document that parameter. Existing docstring entries always take precedence overDoc()descriptions. The type is still unwrapped fromAnnotatedas before for:type:rendering. Detection uses duck-typing on theDocclass identity (module + qualname) to avoid a hard dependency ontyping_extensions.Both Sphinx field list and numpydoc formats are supported — numpydoc converts to Sphinx field list syntax before injection runs, so the
Doclogic works for both without format-specific code.Closes #149