Skip to content

Commit

Permalink
Fix #6589: autodoc: Formatting issues with autodoc_typehints='none'
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Aug 1, 2019
1 parent 4732ec5 commit ace7b4d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Bugs fixed
``__init__()`` and ``__new__()``
* #6574: autodoc: :confval:`autodoc_member_order` does not refer order of
imports when ``'bysource'`` order
* #6589: autodoc: Formatting issues with autodoc_typehints='none'
* #6498: autosummary: crashed with wrong autosummary_generate setting
* #6507: autosummary: crashes without no autosummary_generate setting
* #6511: LaTeX: autonumbered list can not be customized in LaTeX
Expand Down
4 changes: 2 additions & 2 deletions sphinx/util/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def format_args(self, show_annotation: bool = True) -> str:
arg.write(': ')
arg.write(self.format_annotation(param.annotation))
if param.default is not param.empty:
if param.annotation is param.empty:
if param.annotation is param.empty or show_annotation is False:
arg.write('=')
arg.write(object_description(param.default))
else:
Expand All @@ -444,7 +444,7 @@ def format_args(self, show_annotation: bool = True) -> str:
args.append(arg.getvalue())
last_kind = param.kind

if self.return_annotation is inspect.Parameter.empty:
if self.return_annotation is inspect.Parameter.empty or show_annotation is False:
return '(%s)' % ', '.join(args)
else:
if 'return' in self.annotations:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ext_autodoc_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,15 @@ def test_autodoc_typehints_none(app):
'.. py:module:: target.typehints',
'',
'',
'.. py:class:: Math(s, o = None)',
'.. py:class:: Math(s, o=None)',
' :module: target.typehints',
'',
' ',
' .. py:method:: Math.incr(a, b = 1) -> int',
' .. py:method:: Math.incr(a, b=1)',
' :module: target.typehints',
' ',
'',
'.. py:function:: incr(a, b = 1) -> int',
'.. py:function:: incr(a, b=1)',
' :module: target.typehints',
''
]
Expand Down
4 changes: 4 additions & 0 deletions tests/test_util_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ def test_Signature_annotations():
sig = inspect.Signature(Node.__init__).format_args()
assert sig == '(self, parent: Optional[Node]) -> None'

# show_annotation is False
sig = inspect.Signature(f7).format_args(show_annotation=False)
assert sig == '(x=None, y={})'


def test_safe_getattr_with_default():
class Foo:
Expand Down

0 comments on commit ace7b4d

Please sign in to comment.