我已经使用这个文档字符串语法 2 年了,它叫什么,谁指定它,使用它"ok"吗?



我已经使用这种奇怪的语法很长时间了,并且非常擅长它。 这就像把Java的优点放在Python中一样。太棒了,我喜欢它,我的 IDE 甚至因为注释而捕获了一些错误。

但是,我不知道谁指定了这种语法,它有多正式,我也不知道它的确切规则。

诚然,我正在使用 PyCharm,但我不知道这是否适用于其他 IDE,或者它是否只是 PyCharm 语法 - 我不想认为它是,我想使用也适用于其他工具的文档字符串语法。

此外,我看到亚马逊人在他们的python库boto中使用这种语法: https://github.com/boto/boto/blob/develop/boto/beanstalk/layer1.py#L83

下面是语法的示例。

def asdf(name, descriptions, weird_dict):
"""
:type weird_dict: dict[tuple[str|None],list[dict[int,str]|MyClass]]
:param weird_dict: description description
:type name: str
:param list[str] descriptions: Description and type annotation
:param str name: Here I declared the "suggested" type, and can also describe the param
:return:  Here I just describe what's returned
:rtype: int
"""

请告诉我,如果有人知道,这个语法的名称是什么,谁指定它,以及我如何找到有关它的更多信息,因为我尝试了几次,最终进入了 PyCharm 网站。

这是 PEP 287 指定的 reStructuredText Docstring 格式

PyCharm 在 Python 集成工具设置下还具有以下文档字符串格式

  • 平原
  • 埃皮文本
  • 重新结构化文本
  • 数字派
  • 谷歌

相关内容

最新更新