sphinx-autodoc-typehints icon indicating copy to clipboard operation
sphinx-autodoc-typehints copied to clipboard

Missing links for a union with an unevaluated type alias

Open nineteendo opened this issue 1 year ago • 1 comments

It's not a big deal, but I would like the links to the type definitions to be present on all pages: https://jsonyx.readthedocs.io/en/latest/api/jsonyx.apply_patch.html

# conf.py
autodoc_type_aliases = {"_Operation": "_Operation"}
_Operation = dict[str, Any]

def apply_patch(
    obj: Any,
    patch: _Operation | list[_Operation],
    *,
    allow: Container[str] = NOTHING,
    use_decimal: bool = False,
) -> Any:
    ...
Screenshot 2024-09-11 at 20 23 12

nineteendo avatar Sep 11 '24 18:09 nineteendo

typing.get_type_hints() raises this error:

TypeError("unsupported operand type(s) for |: 'TypeAliasForwardRef' and 'types.GenericAlias'")

This seems to fix the issue:

-localns = TypeAliasNamespace(app.config["autodoc_type_aliases"])
+localns = {key: ForwardRef(value) for key, value in app.config["autodoc_type_aliases"].items()}

nineteendo avatar Mar 30 '25 13:03 nineteendo