我有一个类有点像下面。
from joblib import Memory
import time
def find_static_methods(cls):
# to be implemented
pass
class A:
def __init__(self, cache_path: str):
self._memory = Memory(cache_path, verbose=0)
self._methods = {}
for name, method in find_static_methods(A):
self._methods[name] = self._memory.cache(method)
def __getattribute__(self, item):
if item in self._methods:
return self._methods[item]
return super(A, self).__getattribute__(item)
@staticmethod
def method1(a: int, b: int):
time.sleep(3)
return a + b
我正在努力记忆 method1
使用 joblib.Memory
. 但我不知道 cache_path
预告。请帮我落实 find_static_methods
在这里,我有一个类似于以下的类:从joblib导入Memory导入time def find_static_methods(cls): find_static_methods(cls)
下面是另一种方法。
A_attrs = A.__dict__
for k, v in A_attrs.items():
if isinstance(v, staticmethod):
print(k)