mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #7668: autodoc: wrong retann value is passed to autodoc-proccess-signature
This commit is contained in:
parent
63457c700c
commit
dff45a11b7
2
CHANGES
2
CHANGES
@ -90,6 +90,8 @@ Bugs fixed
|
|||||||
* #7362: autodoc: does not render correct signatures for built-in functions
|
* #7362: autodoc: does not render correct signatures for built-in functions
|
||||||
* #7654: autodoc: ``Optional[Union[foo, bar]]`` is presented as
|
* #7654: autodoc: ``Optional[Union[foo, bar]]`` is presented as
|
||||||
``Union[foo, bar, None]``
|
``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
|
* #7551: autosummary: a nested class is indexed as non-nested class
|
||||||
* #7535: sphinx-autogen: crashes when custom template uses inheritance
|
* #7535: sphinx-autogen: crashes when custom template uses inheritance
|
||||||
* #7536: sphinx-autogen: crashes when template uses i18n feature
|
* #7536: sphinx-autogen: crashes when template uses i18n feature
|
||||||
|
@ -389,21 +389,27 @@ class Documenter:
|
|||||||
if self.args is not None:
|
if self.args is not None:
|
||||||
# signature given explicitly
|
# signature given explicitly
|
||||||
args = "(%s)" % self.args
|
args = "(%s)" % self.args
|
||||||
|
retann = self.retann
|
||||||
else:
|
else:
|
||||||
# try to introspect the signature
|
# try to introspect the signature
|
||||||
try:
|
try:
|
||||||
|
retann = None
|
||||||
try:
|
try:
|
||||||
args = self.format_args(**kwargs)
|
args = self.format_args(**kwargs)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# retry without arguments for old documenters
|
# retry without arguments for old documenters
|
||||||
args = self.format_args()
|
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:
|
except Exception:
|
||||||
logger.warning(__('error while formatting arguments for %s:') %
|
logger.warning(__('error while formatting arguments for %s:') %
|
||||||
self.fullname, type='autodoc', exc_info=True)
|
self.fullname, type='autodoc', exc_info=True)
|
||||||
args = None
|
args = None
|
||||||
|
|
||||||
retann = self.retann
|
|
||||||
|
|
||||||
result = self.env.events.emit_firstresult('autodoc-process-signature',
|
result = self.env.events.emit_firstresult('autodoc-process-signature',
|
||||||
self.objtype, self.fullname,
|
self.objtype, self.fullname,
|
||||||
self.object, self.options, args, retann)
|
self.object, self.options, args, retann)
|
||||||
|
@ -161,7 +161,6 @@ def test_format_signature(app):
|
|||||||
pass
|
pass
|
||||||
assert formatsig('function', 'f', f, None, None) == '(a, b, c=1, **d)'
|
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, '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')"
|
assert formatsig('function', 'g', g, None, None) == r"(a='\n')"
|
||||||
|
|
||||||
# test for classes
|
# test for classes
|
||||||
@ -246,6 +245,27 @@ def test_format_signature(app):
|
|||||||
'(b, c=42, *d, **e)'
|
'(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):
|
def test_get_doc(app):
|
||||||
directive = make_directive_bridge(app.env)
|
directive = make_directive_bridge(app.env)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user