mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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
This commit is contained in:
8
tests/roots/test-ext-autodoc/target/wrappedfunction.py
Normal file
8
tests/roots/test-ext-autodoc/target/wrappedfunction.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# for py32 or above
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def slow_function(message, timeout):
|
||||
"""This function is slow."""
|
||||
print(message)
|
||||
@@ -1369,6 +1369,19 @@ def test_partialmethod(app):
|
||||
assert list(actual) == expected
|
||||
|
||||
|
||||
@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 = [
|
||||
|
||||
Reference in New Issue
Block a user