Skip to content

Commit 9b74e6c

Browse files
committed
autodoc: the signature of base function will be shown for decorated functions
1 parent cc4534d commit 9b74e6c

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Dependencies
77
Incompatible changes
88
--------------------
99

10+
* #7650: autodoc: the signature of base function will be shown for decorated
11+
functions, not a signature of decorator
12+
1013
Deprecated
1114
----------
1215

@@ -23,6 +26,8 @@ Bugs fixed
2326
is 'description'
2427
* #7812: autodoc: crashed if the target name matches to both an attribute and
2528
module that are same name
29+
* #7650: autodoc: function signature becomes ``(*args, **kwargs)`` if the
30+
function is decorated by generic decorator
2631
* #7812: autosummary: generates broken stub files if the target code contains
2732
an attribute and module that are same name
2833
* #7806: viewcode: Failed to resolve viewcode references on 3rd party builders

sphinx/ext/autodoc/__init__.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,10 +1157,7 @@ def format_args(self, **kwargs: Any) -> str:
11571157

11581158
try:
11591159
self.env.app.emit('autodoc-before-process-signature', self.object, False)
1160-
if inspect.is_singledispatch_function(self.object):
1161-
sig = inspect.signature(self.object, follow_wrapped=True)
1162-
else:
1163-
sig = inspect.signature(self.object)
1160+
sig = inspect.signature(self.object, follow_wrapped=True)
11641161
args = stringify_signature(sig, **kwargs)
11651162
except TypeError as exc:
11661163
logger.warning(__("Failed to get a function signature for %s: %s"),
@@ -1740,13 +1737,8 @@ def format_args(self, **kwargs: Any) -> str:
17401737
sig = inspect.signature(self.object, bound_method=False)
17411738
else:
17421739
self.env.app.emit('autodoc-before-process-signature', self.object, True)
1743-
1744-
meth = self.parent.__dict__.get(self.objpath[-1], None)
1745-
if meth and inspect.is_singledispatch_method(meth):
1746-
sig = inspect.signature(self.object, bound_method=True,
1747-
follow_wrapped=True)
1748-
else:
1749-
sig = inspect.signature(self.object, bound_method=True)
1740+
sig = inspect.signature(self.object, bound_method=True,
1741+
follow_wrapped=True)
17501742
args = stringify_signature(sig, **kwargs)
17511743
except TypeError as exc:
17521744
logger.warning(__("Failed to get a method signature for %s: %s"),

tests/test_ext_autodoc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ def test_automethod_for_decorated(app):
12671267
actual = do_autodoc(app, 'method', 'target.decorator.Bar.meth')
12681268
assert list(actual) == [
12691269
'',
1270-
'.. py:method:: Bar.meth()',
1270+
'.. py:method:: Bar.meth(name=None, age=None)',
12711271
' :module: target.decorator',
12721272
'',
12731273
]
@@ -1432,7 +1432,7 @@ def test_coroutine(app):
14321432
actual = do_autodoc(app, 'function', 'target.coroutine.sync_func')
14331433
assert list(actual) == [
14341434
'',
1435-
'.. py:function:: sync_func(*args, **kwargs)',
1435+
'.. py:function:: sync_func()',
14361436
' :module: target.coroutine',
14371437
'',
14381438
]

tests/test_ext_autodoc_autofunction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_decorated(app):
9898
actual = do_autodoc(app, 'function', 'target.decorator.foo')
9999
assert list(actual) == [
100100
'',
101-
'.. py:function:: foo()',
101+
'.. py:function:: foo(name=None, age=None)',
102102
' :module: target.decorator',
103103
'',
104104
]

0 commit comments

Comments
 (0)