Skip to content

Commit 47f6e7b

Browse files
committed
Fixed formatting of parametrized IO annotation
Fixes #142.
1 parent 63845fb commit 47f6e7b

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ UNRELEASED
22
==========
33

44
* Dropped support for Sphinx < 3.0
5+
* Fixed ``TypeError`` when formatting a parametrized ``typing.IO`` annotation
6+
57

68
1.10.3
79
======

sphinx_autodoc_typehints.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def get_annotation_class_name(annotation, module: str) -> str:
4242
return annotation.__qualname__
4343
elif getattr(annotation, '_name', None): # Required for generic aliases on Python 3.7+
4444
return annotation._name
45-
elif getattr(annotation, 'name', None) and module in ('typing', 'typing_extensions'):
45+
elif (module in ('typing', 'typing_extensions')
46+
and isinstance(getattr(annotation, 'name', None), str)):
4647
# Required for at least Pattern and Match
4748
return annotation.name
4849

tests/test_sphinx_autodoc_typehints.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def test_parse_annotation(annotation, module, class_name, args):
143143
(Pattern, ':py:class:`~typing.Pattern`'),
144144
(Pattern[str], ':py:class:`~typing.Pattern`\\[:py:class:`str`]'),
145145
(IO, ':py:class:`~typing.IO`'),
146+
(IO[str], ':py:class:`~typing.IO`\\[:py:class:`str`]'),
146147
(Metaclass, ':py:class:`~%s.Metaclass`' % __name__),
147148
(A, ':py:class:`~%s.A`' % __name__),
148149
(B, ':py:class:`~%s.B`' % __name__),
@@ -483,7 +484,7 @@ class dummy_module.DataClass
483484
484485
Class docstring.
485486
486-
__init__() -> None
487+
__init__()
487488
488489
{dataclass_docstring}
489490

0 commit comments

Comments
 (0)