How to¶
Installation¶
$ pip install sphinx-autodoc-typehints-gp
Pipeline position¶
Two hooks run independently:
Event |
Hook |
Priority |
|---|---|---|
|
NumPy section parser |
default (not priority-controlled) |
|
|
499 — before Sphinx’s built-in |
Running at priority 499 means cross-referenced :type:/:rtype: fields are
already in place before Sphinx’s built-in handler runs. The built-in sees them
and skips its own plain-text duplicates — cooperation, not conflict.
Features¶
Resolves type hints statically without
exec()ortyping.get_type_hints().Works perfectly with
TYPE_CHECKINGblocks.No text-level race conditions with Napoleon.
Exposes reusable helpers for annotation display classification and rendered type paragraphs used by the other autodoc packages.
Choosing the right helper¶
Four build_* functions span two axes:
Resolved ( |
Unresolved (annotation text only) |
|
|---|---|---|
Raw paragraph |
|
|
Display-classified |
|
|
Use build_resolved_* inside doctree-resolved event handlers where a
BuildEnvironment is available. Use build_* when you have only the
annotation string.
Annotation display classification¶
classify_annotation_display() returns an AnnotationDisplay with structured
metadata for UI renderers. All values below are verified against the installed
package:
Annotation input |
|
|
|
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_literal_enum=True lets rendering code produce individual badge chips for
each member rather than a monolithic code string. This decision used to live
in each consumer (FastMCP, pytest-fixtures, api-style); now it lives in
classify_annotation_display() so no downstream package re-implements enum
detection heuristics.
Static resolution¶
Approach |
|
Napoleon text-processing race |
|---|---|---|
|
No — resolves at import time |
Yes — depends on import order |
|
Yes — resolves at Sphinx build time |
No — no text processing |
This extension uses sphinx_stringify_annotation() to resolve annotations at
build time, making it safe with TYPE_CHECKING blocks and eliminating
text-processing races with Napoleon.