当我使用参数创建一个函数时,PyCharm让我使用:param param_name:
字段创建文档字符串,这非常好。但我还需要添加:type param_name:
。
从那以后:
def foo(bar, xyz):
return bar + xyz
使用generate docstring选项我有(即使 Insert'type'和'rtype'到文档存根启用):
def foo(bar, xyz):
"""
:param bar:
:param xyz:
"""
return bar + xyz
我希望:
def foo(bar, xyz):
"""
:param bar:
:type bar:
:param xyz:
:type xyz:
"""
return bar + xyz
答案 0 :(得分:8)
Per the documentation:
If configured, the documentation comment stubs can be generated with
type
andrtype
tags.
Following the link:
...
- In the Smart Keys page, select the check box Insert 'type' and 'rtype' to the documentation comment stub.
Once you have done this, put the cursor in a parameter name in the definition, activate the Smart Keys feature (Alt+Enter, by default) and select Specify type for reference in docstring. This will insert the appropriate comment line . Similarly you can put the cursor in the function/method name and select Specify return type in docstring.
答案 1 :(得分:2)
答案 2 :(得分:0)
只需启用此复选框:
编辑器 - 常规 - 智能密钥 - 在文档注释存根中插入类型占位符。
还要记得启用此项目以便您可以使用 Alt + 输入来自动插入文档:
编辑 - 常规 - 智能密钥 - 插入文档评论存根
答案 3 :(得分:0)
What you asked already has been replied but I find relevant to point that you can use
def foo(bar, xyz):
"""
:param bar_type bar:
:param xyz_type xyz:
"""
return bar + xyz
Use indicate bar_type
and xyz_type
the types of the variables. A good tip is that you can use |
to set more than one possible type. Example:
def foo(bar, xyz):
"""
:param float|int bar:
:param numpy.array xyz:
"""
return bar + xyz
答案 4 :(得分:0)
首先,检查您是否启用了 restructuredText 插件。要检查,请转到首选项 - 插件 - restructuredText(如果未启用,请选中该框以启用它) 接下来,在相同的首选项选项卡中,导航到 Tools > Python Integrated Tools > Docstrings
改变Docstring格式:restructuredText(而不是Plain) 另外,选中复选框
最后,要验证更改,请转到功能块并添加三个引号(单引号或双引号)并按 Enter 或空格,您应该会看到自动生成的文档字符串。