注释中多了一行:type
设置为Epytext
PyCharm 2020.3.5 (Community Edition)
同样的函数在pycharm2021下,每个参数都有一行type用来标注数据类型
PyCharm 2021.2 (Professional Edition)
取消方法
- Press and go to Editor | General |Smart Keys | Python.Ctrl+Alt+S
unSelect the Insert type placeholders checkbox in the Smart Keys page of the editor settings.
编辑器 - 常规 - 智能键 - Python,取消勾选 【在文档注释存根中插入类型占位符】
类型放在同一行?
官网提到可以把类型和param放在同一行,原文如下:https://www.jetbrains.com/help/pycharm/using-docstrings-to-specify-types.html#param-type-specification
请注意,对于 reStructuredText,可以用两种格式指定类型:
-
:param param_type param_name: parameter description
(类型描述与参数描述位于同一行)。-
:type param_name: param_type
(类型说明位于单独的行上)
示例代码如下,但我没找到设置方法,我是手动写的,在按下Ctrl+Q出现方法提示中可以看到每个参数的数据类型
在文章中有这样一样方法
- Press and go to Build, Execution, Deployment | Python Debugger. In the Python Debugger page, select the Collect runtime information for code insight checkbox.Ctrl+Alt+S
构建、执行、部署 - Python调试器 - 勾选 【收集运行时类型信息以获取代码洞察】
我在本地这样测试是没有效果,可能是因为我们游戏代码在pycharm中并不能调试
Docstring不会发生改变?
我在pycharm2021下修改Docstring风格不生效,因为切换风格后生成的注释都不会发生改变,比如Epytext,google。
目前还没找到是什么原因引起的。
docstrings是一门标记语言
看了官方每一种docstrings的文档,了解到每一种注释风格都是一门标记语言
Legacy type syntax for docstrings | PyCharm (jetbrains.com)