Fix #7668: autodoc: wrong retann value is passed to autodoc-proccess-signature

This commit is contained in:
Takeshi KOMIYA 2020-05-16 14:51:18 +09:00
parent 63457c700c
commit dff45a11b7
3 changed files with 31 additions and 3 deletions

View File

@ -90,6 +90,8 @@ Bugs fixed
* #7362: autodoc: does not render correct signatures for built-in functions
* #7654: autodoc: ``Optional[Union[foo, bar]]`` is presented as
``Union[foo, bar, None]``
* #7668: autodoc: wrong retann value is passed to a handler of
autodoc-proccess-signature
* #7551: autosummary: a nested class is indexed as non-nested class
* #7535: sphinx-autogen: crashes when custom template uses inheritance
* #7536: sphinx-autogen: crashes when template uses i18n feature

View File

@ -389,21 +389,27 @@ class Documenter:
if self.args is not None:
# signature given explicitly
args = "(%s)" % self.args
retann = self.retann
else:
# try to introspect the signature
try:
retann = None
try:
args = self.format_args(**kwargs)
except TypeError:
# retry without arguments for old documenters
args = self.format_args()
if args:
matched = re.match(r'^(\(.*\))\s+->\s+(.*)$', args)
if matched:
args = matched.group(1)
retann = matched.group(2)
except Exception:
logger.warning(__('error while formatting arguments for %s:') %
self.fullname, type='autodoc', exc_info=True)
args = None
retann = self.retann
result = self.env.events.emit_firstresult('autodoc-process-signature',
self.objtype, self.fullname,
self.object, self.options, args, retann)

View File

@ -161,7 +161,6 @@ def test_format_signature(app):
pass
assert formatsig('function', 'f', f, None, None) == '(a, b, c=1, **d)'
assert formatsig('function', 'f', f, 'a, b, c, d', None) == '(a, b, c, d)'
assert formatsig('function', 'f', f, None, 'None') == '(a, b, c=1, **d) -> None'
assert formatsig('function', 'g', g, None, None) == r"(a='\n')"
# test for classes
@ -246,6 +245,27 @@ def test_format_signature(app):
'(b, c=42, *d, **e)'
def test_autodoc_process_signature_typehints(app):
captured = []
def process_signature(*args):
captured.append(args)
app.connect('autodoc-process-signature', process_signature)
def func(x: int, y: int) -> int:
pass
directive = make_directive_bridge(app.env)
inst = app.registry.documenters['function'](directive, 'func')
inst.fullname = 'func'
inst.object = func
inst.objpath = ['func']
inst.format_signature()
assert captured == [(app, 'function', 'func', func,
directive.genopt, '(x: int, y: int)', 'int')]
def test_get_doc(app):
directive = make_directive_bridge(app.env)