问题描述
我的项目文档正在使用:
我的许多类属性都使用以下装饰器进行装饰:
class cachedproperty(property):
"""
A decorator for implementing cached read-only properties.
"""
def __init__(self,fget=None,fset=None,fdel=None,doc=None):
doc = doc or fget.__doc__
super().__init__(fget,None,doc)
self._func = fget
self._func_name = None
update_wrapper(self,fget)
self._lock = RLock()
def __set_name__(self,owner,name):
if self._func_name is None:
self._func_name = name
elif name != self._func_name:
raise AttributeError(f'Cannot assign the same cached property to two different members: {self._func_name} and {name}.')
def __get__(self,instance,owner=None):
if instance is None:
return self
if self._func_name is None:
raise AttributeError('Cannot use a cached property without calling "__set_name__" on it.')
with self._lock:
try:
return instance.__dict__[self._func_name]
except KeyError:
return instance.__dict__.setdefault(self._func_name,self._func(instance))
def __set__(self,obj,value):
if obj is None:
raise AttributeError('The parameter "obj" is null.')
raise AttributeError('This property cannot be set.')
def deleter(self,fdel):
raise AttributeError('This property cannot implement a deleter.')
def getter(self,fget):
return type(self)(fget,None)
def setter(self,fset):
raise AttributeError('This property cannot implement a setter.')
例如:
@cachedproperty
def my_property(self) -> numpy.ndarray:
"""
A property representing...
"""
value = long_computation()
return value
在查看项目文档时,我看到的是:
返回类型显示两次,在属性名称旁边和属性文档字符串下。第一个返回类型不显示任何类型的链接。有没有办法改变这种行为?这是我想获得的:
我阅读了一些文档,并在谷歌上搜索了很多,但无济于事。有人可以帮我吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)