如何解决Python Sphinx Autodoc Typehints:属性的重复返回类型
我的项目文档正在使用:
我的许多类属性都使用以下装饰器进行装饰:
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 举报,一经查实,本站将立刻删除。