diff options
author | Terence D. Honles <terence@honles.com> | 2020-02-27 16:27:41 -0800 |
---|---|---|
committer | Terence D. Honles <terence@honles.com> | 2020-02-27 16:27:41 -0800 |
commit | 90de551d4cfc206450cbd776cd1a14512ae3f0a4 (patch) | |
tree | 9a763c7b54ed953fce50fb463ab9bf325fe240db /tests/test_autodoc.py | |
parent | 87fd65fd313a97e35deb717ca861d269f741afbf (diff) | |
download | sphinx-git-90de551d4cfc206450cbd776cd1a14512ae3f0a4.tar.gz |
Fix: autodoc: `__wrapped__` functions are not documented correctly
Functions that are decorated with `@lru_cache` or other `functools`
decorators may not even be detected as a function. This results in the
documentation not having the `()` or even trying to render the function
signature.
This change updates the `sphinx.util.inspect` code to unwrap
`__wrapped__` functions before determining if they can be documented.
`@lru_cache` and its associated test is an example of a decorated
function that is incorrectly identified as an attribute rather than a
module level function and when rendering the signature (upon changing
`isattributedescriptor`) the decorated function is still incorrectly
identified as a C function.
This change also renames the newly introduced `unwrap` as `unwrap_all`
because it is different than the prexisting Python supplied
`inspect.unwrap`.
See `update_wrapper` "Changed in version 3.4" for more background:
https://docs.python.org/3/library/functools.html#functools.update_wrapper
Diffstat (limited to 'tests/test_autodoc.py')
-rw-r--r-- | tests/test_autodoc.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index a86211f18..cb93b47e1 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -1370,6 +1370,19 @@ def test_partialmethod(app): @pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_wrappedfunction(app): + actual = do_autodoc(app, 'function', 'target.wrappedfunction.slow_function') + assert list(actual) == [ + '', + '.. py:function:: slow_function(message, timeout)', + ' :module: target.wrappedfunction', + '', + ' This function is slow.', + ' ', + ] + + +@pytest.mark.sphinx('html', testroot='ext-autodoc') def test_partialmethod_undoc_members(app): expected = [ '', |