Fix #7650: autodoc: undecorated signature is shown for decorated functions

This commit is contained in:
Takeshi KOMIYA
2020-05-10 23:10:18 +09:00
parent 1771bbb927
commit 3a81ffa79a
6 changed files with 68 additions and 13 deletions

View File

@@ -1,5 +1,9 @@
from functools import wraps
def deco1(func):
"""docstring for deco1"""
@wraps(func)
def wrapper():
return func()
@@ -14,3 +18,14 @@ def deco2(condition, message):
return wrapper
return decorator
@deco1
def foo(name=None, age=None):
pass
class Bar:
@deco1
def meth(self, name=None, age=None):
pass

View File

@@ -142,6 +142,7 @@ def test_format_signature(app):
inst = app.registry.documenters[objtype](directive, name)
inst.fullname = name
inst.doc_as_attr = False # for class objtype
inst.parent = object # dummy
inst.object = obj
inst.objpath = [name]
inst.args = args
@@ -1243,6 +1244,17 @@ def test_autofunction_for_methoddescriptor(app):
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autofunction_for_decorated(app):
actual = do_autodoc(app, 'function', 'target.decorator.foo')
assert list(actual) == [
'',
'.. py:function:: foo()',
' :module: target.decorator',
'',
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_automethod_for_builtin(app):
actual = do_autodoc(app, 'method', 'builtins.int.__add__')
@@ -1256,6 +1268,17 @@ def test_automethod_for_builtin(app):
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_automethod_for_decorated(app):
actual = do_autodoc(app, 'method', 'target.decorator.Bar.meth')
assert list(actual) == [
'',
'.. py:method:: Bar.meth()',
' :module: target.decorator',
'',
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_abstractmethods(app):
options = {"members": None,
@@ -1415,7 +1438,7 @@ def test_coroutine(app):
actual = do_autodoc(app, 'function', 'target.coroutine.sync_func')
assert list(actual) == [
'',
'.. py:function:: sync_func()',
'.. py:function:: sync_func(*args, **kwargs)',
' :module: target.coroutine',
'',
]

View File

@@ -97,7 +97,7 @@ def test_signature_methods():
# wrapped bound method
sig = inspect.signature(wrapped_bound_method)
assert stringify_signature(sig) == '(arg1, **kwargs)'
assert stringify_signature(sig) == '(*args, **kwargs)'
def test_signature_partialmethod():