mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7669 from tk0miya/7668_wront_retann
Fix #7668: autodoc: wrong retann value is passed to autodoc-proccess-signature
This commit is contained in:
commit
6a4148abec
2
CHANGES
2
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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user