-
Notifications
You must be signed in to change notification settings - Fork 878
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
Pass documentation around. #3656
Conversation
266a92c
to
dae7a27
Compare
I double checked the docs and I don't see anything wrong with our usage of |
@luhn update_wrapper is meant to be a decorator too: https://github.com/python/cpython/blob/master/Lib/functools.py#L25-L78
Actually I am wrong about that and you are right. I don't know why this PR fixes it then 😕 |
dae7a27
to
2854add
Compare
@@ -36,6 +36,7 @@ class reify: | |||
def __init__(self, wrapped): | |||
self.wrapped = wrapped | |||
update_wrapper(self, wrapped) | |||
self.__doc__ = wrapped.__doc__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update_wrapper is supposed to do it 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty clear, as you said, that update_wrapper is supposed to do it and is also more defensive about doing it than this code (i.e. if wrapped
doesn't have a doc attr for some insane reason). I'd want to know why the expected version isn't working first if you could step through update_wrapper and determine why it's not setting this itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe that's why, this would set it to None
if not defined which would help Sphinx to find it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this there's no tests for None
, it's just pulling the value and setting it.
https://github.com/python/cpython/blob/3.9/Lib/functools.py#L50-L56
This The issue is that sphinx uses isattributedescriptor to determine if a descriptor represents an attribute or not. import inspect
from pyramid.decorator import reify
from functools import cached_property
from sphinx.util.inspect import isattributedescriptor
class Widget:
@property
def prop(self):
return 'Foo'
@cached_property
def cached(self):
return 'Foo'
@reify
def reify(self):
return 'Foo'
print(isattributedescriptor(Widget.prop))
print(isattributedescriptor(Widget.cached))
print(isattributedescriptor(Widget.reify)) Output is:
So Sphinx doesn't recognize |
Funny, I think the problem is that we're using So @Natim, your fix using |
Thank you for your great analysis. Feel free to update the PR if you want or I will be able to do it in about 10 hours. 🙏 |
Made the change in #3657 |
Fixes #3655
Use wraps which also link the documentation.