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

sphinx documentation with methodtools.lru_cache #1

Open
jbloom opened this issue Oct 24, 2019 · 11 comments · Fixed by #2
Open

sphinx documentation with methodtools.lru_cache #1

jbloom opened this issue Oct 24, 2019 · 11 comments · Fixed by #2

Comments

@jbloom
Copy link

jbloom commented Oct 24, 2019

When I decorate a method with methodtools.lru_cache and then build sphinx documentation, the docstring shows as <methodtools._LruCacheWire object> rather than the documentation for the method in its docstring.

I think this type of problem is addressed here, but I can't figure out how to modify methodtools to fix the problem.

@youknowone
Copy link
Owner

youknowone commented Oct 26, 2019

Thanks for reporting missing feature.
Because it is implemented out of methodtools project, I made a PR to wirerope.
youknowone/wirerope#5

Unfortunately, I made working version for methods but not about properties yet.

@youknowone
Copy link
Owner

I released 0.1.2 with this document fix: https://pypi.org/project/methodtools/0.1.2/
Will you test it please?

@jbloom
Copy link
Author

jbloom commented Oct 26, 2019

This did not seem to fix the problem for me.

@youknowone youknowone reopened this Oct 27, 2019
@youknowone
Copy link
Owner

I wanted to test this problem with actual example of sphinx but didn't have enough time to do that.
Do you know any small and simple sphinx example proejct?

@lisphilar
Copy link

Dear @youknowone ,
Thank you for your helpful package.
I started to use methodtools in my project and found the same issue.
https://lisphilar.github.io/covid19-sir/covsirphy.cleaning.html#covsirphy.cleaning.term.Term.num2str

Do we need to create a new decorator to show the docstring?
Please help me out.

@youknowone
Copy link
Owner

youknowone commented Jul 26, 2020

Sorry for late fix. I want to fix this problem but almost forgot about it for a while. I think wrapping once more will be a simple workaround for simple use case, if you don't use cache_info()

image

It seems sphinx doesn't support function-like object. I need to dig in sphinx a bit.

@lisphilar
Copy link

Dear @youknowone ,
Thank you for your prompt reply!
I tried the following code.

from methodtools import lru_cache

def show_info(func):
    def wrapper(*args, **kwargs):
        return func.cache_info(*args, **kwargs)
    return wrapper


class ClassA(object):
    @show_info
    @lru_cache(maxsize=None)
    def method_a(self, arg1):
        """
        This may be a method to do something.
        """
        pass

In sphinx document, <methodtools._LruCacheWire object> was successfully removed!
However, it shows method_a(**kwargs) even when arguments (arg1) exist. Docsting was not shown.
Sorry for asking basic question of decorator, but please tell me how to improve it.

@youknowone
Copy link
Owner

I don't think you need cache_info here. Check this way: https://docs.python.org/3/library/functools.html#functools.wraps

@lisphilar
Copy link

Dear @youknowone ,
I'm sorry, but I couldn't find the solution in my project.
Please clarify the solution with the example codes I used in the previous comment.

@youknowone
Copy link
Owner

It seems sphinx only support actual functions

@lisphilar
Copy link

Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants