我发现这很烦人,因为快速文档不显示类的文档中列出的属性。我以为原因不正确或文档字符串格式不受支持,但是reST
和Google
样式的行为都是相同的(我在Python Integrated Tools
中正确设置了样式)。
我当前的文档字符串样式为Google
。让我来说明图片有什么问题:
这里是Actor
类。
如您所见,
Attributes
部分以docstring出现,但没有出现在Quick Documentation弹出窗口中。
此外,属性world_id
上没有注释。
Args
的 __init__
就像是一个咒语。
让我们直接将docstring添加到属性(在answer中如何建议)。效果很好,不是吗?
然后在另一个方法内调用快速文档获取属性。哇,再也没有描述了。
如何使事情正常运行?如何设置PyCharm,使其赶上课堂的属性并在快速文档中显示它们?
PyCharm 2018.2.4(社区版)。 Ubuntu 16.04。
答案 0 :(得分:2)
对于那些仍在为此奋斗并且偶然发现这篇文章的人(像我一样)。
PyCharm目前不支持它-或者我还是应该说。不适用于Google样式的文档字符串,也不适用于StructuralText。在他们的Youtrack支持网站上有关于此问题的多张票。
例如https://youtrack.jetbrains.com/issue/PY-17945-这个问题已经存在了5年以上!
答案 1 :(得分:2)
以下是我如何在 Pycharm 2020.3.3(我使用专业版)的 Docstring 中显示类属性:
class TestModel(models.Model):
"""
A Test model to see the class attributes in the docstring
Attributes:
- :class:`str` name --> The name of the test object
- :class:`datetime` created_at --> Date and time when the instance was created
"""
name = models.CharField(max_length=50)
created_at = models.DateTimeField(auto_now_add=True)
请注意,如果没有 Attributes:
行,它将无法按预期工作。
这就是它在快速文档中的显示方式: