methodtools
methodtools copied to clipboard
sphinx documentation with `methodtools.lru_cache`
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.
Thanks for reporting missing feature. Because it is implemented out of methodtools project, I made a PR to wirerope. https://github.com/youknowone/wirerope/pull/5
~Unfortunately, I made working version for methods but not about properties yet.~
I released 0.1.2 with this document fix: https://pypi.org/project/methodtools/0.1.2/ Will you test it please?
This did not seem to fix the problem for me.
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?
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.
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()

It seems sphinx doesn't support function-like object. I need to dig in sphinx a bit.
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.
I don't think you need cache_info here. Check this way: https://docs.python.org/3/library/functools.html#functools.wraps
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.
It seems sphinx only support actual functions
Thank you for your help.