Skip to content

Commit aeb57c2

Browse files
committed
Fixed return type of __init__ being added (from -> None annotation).
Fixed generic arguments of some types not being added (e.g. typing.Mapping).
1 parent 56b478b commit aeb57c2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

sphinx_autodoc_typehints.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ def format_annotation(annotation):
3030
ellipsis = annotation.__tuple_use_ellipsis__
3131
else:
3232
params = getattr(annotation, '__parameters__', None)
33-
34-
if params:
35-
formatted_params = list(format_annotation(param) for param in params)
33+
if not params:
34+
params = getattr(annotation, '__args__', None)
35+
if params is Ellipsis:
36+
ellipsis = True
37+
params = []
38+
39+
if params or ellipsis:
40+
formatted_params = list(format_annotation(param) for param in (params or []))
3641
if ellipsis:
3742
formatted_params.append('...')
3843
extra = '\\[' + ', '.join(formatted_params) + ']'
@@ -76,6 +81,8 @@ def process_docstring(app, what, name, obj, options, lines):
7681
formatted_annotation = format_annotation(annotation)
7782

7883
if argname == 'return':
84+
if what in ('class', 'exception'):
85+
continue # Don't add return type None from __init__
7986
insert_index = len(lines)
8087
for i, line in enumerate(lines):
8188
if line.startswith(':rtype:'):

0 commit comments

Comments
 (0)