我已经使用这个 docstring 语法 2 年了,它叫什么,谁指定的,它是否“好"?使用它? [英] I've been using this docstring syntax for 2 years now, what's it called, who specifies it, and is it "ok" to use it?
问题描述
我已经使用这种奇怪的语法很长时间了,而且我已经很擅长了.这就像将 Java 的优点放在了 Python 中.太棒了,我喜欢,我的IDE甚至因为注释而发现了一些错误.
I've been using this weird syntax for a long time now, and am getting quite good at it. It's like taking the good part about java, and having that in Python. It's awesome, I like it, my IDE even caught some bugs because of the annotations.
但是我不知道是谁指定了这个语法,它的官方程度,我也不知道它的确切规则.
I don't know however who specified this syntax, how official it is, and I don't know the exact rules for it.
诚然,我正在使用 PyCharm,但我不知道这是否适用于其他 IDE,或者它是否只是 PyCharm 语法 - 我不想认为它是,我想使用也适用于其他工具的 docstring 语法.
Admittedly, I'm using PyCharm, but I don't know if this would work in other IDEs, or if it's just PyCharm syntax - I don'w want to think it is, and I'd like to use a docstring syntax that works for other tools as well.
此外,我看到亚马逊人在他们的 python 库 boto 中使用这种语法:https://github.com/boto/boto/blob/develop/boto/beanstalk/layer1.py#L83
Moreover, I see the amazon people using this kind of syntax in their python library 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 站点上.
Please tell me, if anyone knows, what is the name of this syntax, who specifies it, and how I can find more info about it, because I tried a few times and just ended up on the PyCharm site.
推荐答案
即 由 PEP 287 指定的 reStructuredText Docstring 格式
PyCharm 在 Python 集成工具 设置
PyCharm also has the following docstring formats under the Python Integrated Tools settings
这篇关于我已经使用这个 docstring 语法 2 年了,它叫什么,谁指定的,它是否“好"?使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!