From a9da0288787e6a17d9611a4ac5ca8536c53dd108 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sat, 14 Jan 2023 19:20:11 -0800 Subject: [PATCH] If module is _io, use io instead Most of the io module is implemented in the private C extension module called _io. It would be friendly if Python set the module name to io to match the way it is documented but they don't. --- src/sphinx_autodoc_typehints/__init__.py | 3 +++ tests/test_sphinx_autodoc_typehints.py | 1 + 2 files changed, 4 insertions(+) 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`"),