Skip to content

Commit 26a1416

Browse files
author
Wannes Boeykens
committed
Fix issue #481
1 parent df9520c commit 26a1416

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/sphinx_autodoc_typehints/__init__.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from sphinx.ext.autodoc.mock import mock
1818
from sphinx.parsers import RSTParser
1919
from sphinx.util import logging, rst
20-
from sphinx.util.inspect import TypeAliasForwardRef, TypeAliasNamespace, stringify_signature
20+
from sphinx.util.inspect import stringify_signature
2121
from sphinx.util.inspect import signature as sphinx_signature
2222

2323
from ._parser import parse
@@ -222,9 +222,6 @@ def format_annotation(annotation: Any, config: Config, *, short_literals: bool =
222222
if isinstance(annotation, tuple):
223223
return format_internal_tuple(annotation, config)
224224

225-
if isinstance(annotation, TypeAliasForwardRef):
226-
return annotation.name
227-
228225
try:
229226
module = get_annotation_module(annotation)
230227
class_name = get_annotation_class_name(annotation, module)
@@ -446,7 +443,7 @@ def _future_annotations_imported(obj: Any) -> bool:
446443

447444

448445
def get_all_type_hints(
449-
autodoc_mock_imports: list[str], obj: Any, name: str, localns: TypeAliasNamespace
446+
autodoc_mock_imports: list[str], obj: Any, name: str, localns: dict[str, ForwardRef]
450447
) -> dict[str, Any]:
451448
result = _get_type_hint(autodoc_mock_imports, name, obj, localns)
452449
if not result:
@@ -517,7 +514,7 @@ def _resolve_type_guarded_imports(autodoc_mock_imports: list[str], obj: Any) ->
517514
_execute_guarded_code(autodoc_mock_imports, obj, module_code)
518515

519516

520-
def _get_type_hint(autodoc_mock_imports: list[str], name: str, obj: Any, localns: TypeAliasNamespace) -> dict[str, Any]:
517+
def _get_type_hint(autodoc_mock_imports: list[str], name: str, obj: Any, localns: dict[str, ForwardRef]) -> dict[str, Any]:
521518
_resolve_type_guarded_imports(autodoc_mock_imports, obj)
522519
try:
523520
result = get_type_hints(obj, None, localns)
@@ -689,7 +686,7 @@ def process_docstring( # noqa: PLR0913, PLR0917
689686
except (ValueError, TypeError):
690687
signature = None
691688

692-
localns = TypeAliasNamespace(app.config["autodoc_type_aliases"])
689+
localns = {key: ForwardRef(value) for key, value in app.config["autodoc_type_aliases"].items()}
693690
type_hints = get_all_type_hints(app.config.autodoc_mock_imports, obj, name, localns)
694691
app.config._annotation_globals = getattr(obj, "__globals__", {}) # noqa: SLF001
695692
try:

0 commit comments

Comments
 (0)