Skip to main content
 首页 » 编程设计

python之我已经使用这个 docstring 语法 2 年了,它叫什么,谁指定的,使用它是 "ok"吗

2024年10月01日8落叶无声

我已经使用这种奇怪的语法很长时间了,而且我已经很擅长了。 这就像在 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 站点。

请您参考如下方法:

即reStructuredText Docstring Format按照 PEP 287 的规定

PyCharm 在 Python Integrated Tools 下还有以下文档字符串格式设置