diff --git a/CHANGES b/CHANGES index 4f730e798..7ce281222 100644 --- a/CHANGES +++ b/CHANGES @@ -100,6 +100,8 @@ Bugs fixed * #7676: autodoc: typo in the default value of autodoc_member_order * #7676: autodoc: wrong value for :member-order: option is ignored silently * #7676: autodoc: member-order="bysource" does not work for C module +* #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 * #7661: autosummary: autosummary directive emits warnings twices if failed to import the target module diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 87ab5a7a0..f9c775f7d 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -400,21 +400,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) diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py index 4ed4a9b05..50d641dc9 100644 --- a/tests/test_ext_autodoc.py +++ b/tests/test_ext_autodoc.py @@ -162,7 +162,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 @@ -247,6 +246,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)