Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autodoc: the signature of base function will be shown for decorated functions #7916

Merged
merged 1 commit into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Dependencies
Incompatible changes
--------------------

* #7650: autodoc: the signature of base function will be shown for decorated
functions, not a signature of decorator

Deprecated
----------

Expand All @@ -23,6 +26,8 @@ Bugs fixed
is 'description'
* #7812: autodoc: crashed if the target name matches to both an attribute and
module that are same name
* #7650: autodoc: function signature becomes ``(*args, **kwargs)`` if the
function is decorated by generic decorator
* #7812: autosummary: generates broken stub files if the target code contains
an attribute and module that are same name
* #7806: viewcode: Failed to resolve viewcode references on 3rd party builders
Expand Down
14 changes: 3 additions & 11 deletions sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,10 +1157,7 @@ def format_args(self, **kwargs: Any) -> str:

try:
self.env.app.emit('autodoc-before-process-signature', self.object, False)
if inspect.is_singledispatch_function(self.object):
sig = inspect.signature(self.object, follow_wrapped=True)
else:
sig = inspect.signature(self.object)
sig = inspect.signature(self.object, follow_wrapped=True)
Copy link
Contributor

@harupy harupy Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tk0miya Should we specify follow_wrapeed=True in inspect.signature in ClassDocumenter as well otherwise a wrapper function's signature (e.g. (*args, **kwargs)) would be used when __init__ is decorated?

sig = inspect.signature(init, bound_method=True)

Copy link
Contributor

@harupy harupy Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same goes for the line below:

sig = inspect.signature(obj, bound_method)

args = stringify_signature(sig, **kwargs)
except TypeError as exc:
logger.warning(__("Failed to get a function signature for %s: %s"),
Expand Down Expand Up @@ -1740,13 +1737,8 @@ def format_args(self, **kwargs: Any) -> str:
sig = inspect.signature(self.object, bound_method=False)
else:
self.env.app.emit('autodoc-before-process-signature', self.object, True)

meth = self.parent.__dict__.get(self.objpath[-1], None)
if meth and inspect.is_singledispatch_method(meth):
sig = inspect.signature(self.object, bound_method=True,
follow_wrapped=True)
else:
sig = inspect.signature(self.object, bound_method=True)
sig = inspect.signature(self.object, bound_method=True,
follow_wrapped=True)
args = stringify_signature(sig, **kwargs)
except TypeError as exc:
logger.warning(__("Failed to get a method signature for %s: %s"),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ext_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ def test_automethod_for_decorated(app):
actual = do_autodoc(app, 'method', 'target.decorator.Bar.meth')
assert list(actual) == [
'',
'.. py:method:: Bar.meth()',
'.. py:method:: Bar.meth(name=None, age=None)',
' :module: target.decorator',
'',
]
Expand Down Expand Up @@ -1432,7 +1432,7 @@ def test_coroutine(app):
actual = do_autodoc(app, 'function', 'target.coroutine.sync_func')
assert list(actual) == [
'',
'.. py:function:: sync_func(*args, **kwargs)',
'.. py:function:: sync_func()',
' :module: target.coroutine',
'',
]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ext_autodoc_autofunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_decorated(app):
actual = do_autodoc(app, 'function', 'target.decorator.foo')
assert list(actual) == [
'',
'.. py:function:: foo()',
'.. py:function:: foo(name=None, age=None)',
' :module: target.decorator',
'',
]
Expand Down