diff --git a/src/sphinx_autodoc_typehints/__init__.py b/src/sphinx_autodoc_typehints/__init__.py index 8aa7d4dc..2311133d 100644 --- a/src/sphinx_autodoc_typehints/__init__.py +++ b/src/sphinx_autodoc_typehints/__init__.py @@ -139,6 +139,9 @@ def format_annotation(annotation: Any, config: Config) -> str: # noqa: C901 # t if module == "typing_extensions": module = "typing" + if module == "_io": + module = "io" + full_name = f"{module}.{class_name}" if module != "builtins" else class_name fully_qualified: bool = getattr(config, "typehints_fully_qualified", False) prefix = "" if fully_qualified or full_name == class_name else "~" diff --git a/tests/test_sphinx_autodoc_typehints.py b/tests/test_sphinx_autodoc_typehints.py index acb483b3..2e213dd1 100644 --- a/tests/test_sphinx_autodoc_typehints.py +++ b/tests/test_sphinx_autodoc_typehints.py @@ -180,6 +180,7 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t [ (str, ":py:class:`str`"), (int, ":py:class:`int`"), + (StringIO, ":py:class:`~io.StringIO`"), (type(None), ":py:obj:`None`"), (type, ":py:class:`type`"), (collections.abc.Callable, ":py:class:`~collections.abc.Callable`"),