[英]Pycharm docstring: How to add types into docstring with typing [duplicate]
在 vscode 中,我安装autoDocstring
插件,它可以生成基于Typing
类型的文档。 如下所示:
def split_dataset(
data: torch_geometric.data.Data,
train: float = 0.1,
test: float = 0.8,
val: float = 0.1,
) -> tuple:
"""_summary_
Parameters
----------
data : torch_geometric.data.Data
_description_
train : float, optional
_description_, by default 0.1
test : float, optional
_description_, by default 0.8
val : float, optional
_description_, by default 0.1
Returns
-------
tuple
_description_
"""
pass
但是在 pycharm 中,我尝试使用 docstring,它不会自动生成类型,如下所示:
def split_dataset(
data: torch_geometric.data.Data,
train: float = 0.1,
test: float = 0.8,
val: float = 0.1,
) -> tuple:
"""
Parameters
----------
data :
train :
test :
val :
Returns
-------
"""
pass
有什么办法让 pycharm 做和 vscode 一样的事情吗?
在 PyCharm 中只有一种半自动的方法可以做到这一点。 大多数文档字符串存根可以自动生成,但您需要提供类型。
这里有一个关于如何执行此操作的官方示例
TL;博士
1. Press ⌘ + , and go to Editor | General | Smart Keys.
2. Select the Insert type placeholders checkbox in the Smart Keys page of the editor settings.
3. Place the caret at the function name, and press ⌥ ⏎.
4. In the list of intention actions that opens, choose Insert documentation string stub. PyCharm creates a documentation stub, according to the selected docstring format, with the type specification, collected during the debugger session.
然后,手动指定所需的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.