Skip to content

Commit 3ecdb42

Browse files
authored
If module is _io, use io instead (#291)
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.
1 parent 4ab116d commit 3ecdb42

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def format_annotation(annotation: Any, config: Config) -> str: # noqa: C901 # t
139139
if module == "typing_extensions":
140140
module = "typing"
141141

142+
if module == "_io":
143+
module = "io"
144+
142145
full_name = f"{module}.{class_name}" if module != "builtins" else class_name
143146
fully_qualified: bool = getattr(config, "typehints_fully_qualified", False)
144147
prefix = "" if fully_qualified or full_name == class_name else "~"

tests/test_sphinx_autodoc_typehints.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
180180
[
181181
(str, ":py:class:`str`"),
182182
(int, ":py:class:`int`"),
183+
(StringIO, ":py:class:`~io.StringIO`"),
183184
(type(None), ":py:obj:`None`"),
184185
(type, ":py:class:`type`"),
185186
(collections.abc.Callable, ":py:class:`~collections.abc.Callable`"),

0 commit comments

Comments
 (0)