Skip to content

Conversation

@terencehonles
Copy link
Contributor

Bugfix

Related: #7189 (not caused by, and just fixed with #7189)
Maybe related: #6573

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

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
Copy link
Member

@tk0miya tk0miya left a comment

Choose a reason for hiding this comment

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

LGTM with nits.

@tk0miya tk0miya added extensions:autodoc type:enhancement enhance or introduce a new feature labels Feb 29, 2020
@tk0miya tk0miya added this to the 2.4.4 milestone Feb 29, 2020
@tk0miya tk0miya modified the milestones: 2.4.4, 2.4.5 Mar 5, 2020
@tk0miya tk0miya merged commit 0efcd95 into sphinx-doc:2.4.x Mar 28, 2020
tk0miya added a commit that referenced this pull request Mar 28, 2020
@terencehonles terencehonles deleted the fix-functools.__wrapped__-functions branch April 8, 2020 05:32
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

extensions:autodoc type:bug type:enhancement enhance or introduce a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants