Skip to content

Commit 645fa6b

Browse files
committed
Fixed TypeError with a class that inherits from a concrete generic type
Closes #67.
1 parent cd822aa commit 645fa6b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.rst

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
UNRELEASED
2+
==========
3+
4+
* Fixed ``TypeError`` when formatting annotations from a class that inherits from a concrete
5+
generic type (report and tests by bpeake-illuscio)
6+
7+
18
1.5.2
29
=====
310

sphinx_autodoc_typehints.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ def format_annotation(annotation):
119119
if Generic in annotation_cls.mro():
120120
params = (getattr(annotation, '__parameters__', None) or
121121
getattr(annotation, '__args__', None))
122-
extra = '\\[{}]'.format(', '.join(format_annotation(param) for param in params))
122+
if params:
123+
extra = '\\[{}]'.format(', '.join(format_annotation(param) for param in params))
124+
else:
125+
extra = ''
123126

124127
return ':py:class:`~{}.{}`{}'.format(annotation.__module__, annotation_cls.__qualname__,
125128
extra)

tests/test_sphinx_autodoc_typehints.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class B(Generic[T]):
2121
pass
2222

2323

24+
class C(B[str]):
25+
pass
26+
27+
2428
class Slotted:
2529
__slots__ = ()
2630

@@ -71,7 +75,8 @@ class Slotted:
7175
(Pattern[str], ':py:class:`~typing.Pattern`\\[:py:class:`str`]'),
7276
(A, ':py:class:`~%s.A`' % __name__),
7377
(B, ':py:class:`~%s.B`\\[\\~T]' % __name__),
74-
(B[int], ':py:class:`~%s.B`\\[:py:class:`int`]' % __name__)
78+
(B[int], ':py:class:`~%s.B`\\[:py:class:`int`]' % __name__),
79+
(C, ':py:class:`~%s.C`' % __name__)
7580
])
7681
def test_format_annotation(annotation, expected_result):
7782
result = format_annotation(annotation)

0 commit comments

Comments
 (0)