Skip to content

Commit 536ded1

Browse files
committed
Added support for alternative parameter names
Fixes #144.
1 parent 38b61b4 commit 536ded1

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

CHANGELOG.rst

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

44
* Dropped support for Sphinx < 3.0
5+
* Added support for alternative parameter names (``arg``, ``argument``, ``parameter``)
56
* Fixed ``TypeError`` when formatting a parametrized ``typing.IO`` annotation
67
* Fixed data class displaying a return type in its ``__init__()`` method
78

sphinx_autodoc_typehints.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,17 @@ def process_docstring(app, what, name, obj, options, lines):
372372
formatted_annotation = format_annotation(
373373
annotation, fully_qualified=app.config.typehints_fully_qualified)
374374

375-
searchfor = ':param {}:'.format(argname)
375+
searchfor = [':{} {}:'.format(field, argname)
376+
for field in ('param', 'parameter', 'arg', 'argument')]
376377
insert_index = None
377378

378379
for i, line in enumerate(lines):
379-
if line.startswith(searchfor):
380+
if any(line.startswith(search_string) for search_string in searchfor):
380381
insert_index = i
381382
break
382383

383384
if insert_index is None and app.config.always_document_param_types:
384-
lines.append(searchfor)
385+
lines.append(':param {}:'.format(argname))
385386
insert_index = len(lines)
386387

387388
if insert_index is not None:

tests/roots/test-dummy/dummy_module.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def function_with_unresolvable_annotation(x: 'a.b.c'): # noqa: F821
142142
"""
143143
Function docstring.
144144
145-
:param x: foo
145+
:arg x: foo
146146
"""
147147

148148

@@ -154,7 +154,7 @@ def function_with_typehint_comment(
154154
"""
155155
Function docstring.
156156
157-
:param x: foo
157+
:parameter x: foo
158158
:param y: bar
159159
"""
160160

@@ -181,7 +181,7 @@ def foo(
181181
"""
182182
Method docstring.
183183
184-
:param x: foo
184+
:arg x: foo
185185
"""
186186
return 42
187187

@@ -191,10 +191,10 @@ def function_with_typehint_comment_not_inline(x=None, *y, z, **kwargs):
191191
"""
192192
Function docstring.
193193
194-
:param x: foo
195-
:param y: bar
196-
:param z: baz
197-
:param kwargs: some kwargs
194+
:arg x: foo
195+
:argument y: bar
196+
:parameter z: baz
197+
:parameter kwargs: some kwargs
198198
"""
199199

200200

0 commit comments

Comments
 (0)