setter参数的类型未在狮身人面表文档中显示
我不知道如何使类型提示出现在seters参数的狮身人面像生成的文档中。
我有一个python类,带有一个名为批处理的属性,并且在属性中有Docstrings,并在setter参数(int)中键入暗示。以下是最小示例,但是
class Settings:
"""Settings used"""
def __init__(self):
self._batches = None
@property
def batches(self):
"""Number of batches to simulate"""
return self._batches
@batches.setter
def batches(self, batches: int):
self._batches = batches
使用以下命令。
sphinx-build -b html ./source/ ./build/html/
我正在使用sphinx构建文档,并在 conf.py 我在拿破仑文档所建议的拿破仑包之前有“ sphinx_autodoc_typehints”软件包。我还尝试将其放在检查之后:-)
.. autosummary::
:toctree: generated
:nosignatures:
:template: myclass.rst
docs 正在构建,但类型提示没有出现:
I can't figure out how to get the type hints to appear in the Sphinx generated documentation from setters arguments.
I have a Python class with an attribute called batches and I've got docstrings in the property and type hinting in the setter argument (int). Below is the minimal example, but here is the full version
class Settings:
"""Settings used"""
def __init__(self):
self._batches = None
@property
def batches(self):
"""Number of batches to simulate"""
return self._batches
@batches.setter
def batches(self, batches: int):
self._batches = batches
I'm building documentation with sphinx and using the following command
sphinx-build -b html ./source/ ./build/html/
In the conf.py I have the "sphinx_autodoc_typehints" package before the napoleon package as suggested by the sphinx docs. I have also tried putting it after just to check :-)
In the docs I am using :autosummary:
.. autosummary::
:toctree: generated
:nosignatures:
:template: myclass.rst
The docs are building but the type hints are not appearing:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用装饰器制造的属性与属性相同。这不是一个函数。狮身人面像对此表示敬意。实际上,sphinx仅读取
@property
方法的文档,而不是@property.setter.setter
完全。在您的情况下,指定基本属性的类型提示就足够了。
如果您的二传手接受其他类型(例如浮点,字符串等)并设法将此输入作为内部投入,则可以将其作为基本属性中的散文记录,例如。
A property made using the decorators is for all purposes the same as an attribute. It is not a function. Sphinx honors this. Actually, Sphinx only read the documentation for the
@property
method, not the@property.setter
one at all.In your case, specifying a type hint for the base property should be enough.
In case your setter accepts other types (like floats, strings, etc) and manage to cast this input as an int internally, you can document that as prose in the base property, like so.