在Pycharm中,我希望有一个记录的函数,它返回一个元组,以便我可以在其上获得代码完成。评论的风格是谷歌风格。
这工作正常:
def func():
"""
Returns:
str: something
"""
pass
正确地键入func().
显示str
的方法。
但是,输入此内容不再有效:
def func():
"""
Returns:
(int, str): something
"""
pass
a, b = func()
打字b.
不提供任何东西。
我知道PyCharm能够解析元组,因为这段代码有效:
def func():
"""
:rtype: (int, str)
"""
pass
a, b = func()
但是,这不符合谷歌的风格。
如何根据标准记录函数,以便Pycharm接收返回类型?
来自sphinxcontrib的doc页面
Returns
部分支持任何reStructuredText格式, 包括文字块::{ 'param1': param1, 'param2': param2 }
这表示Google风格支持里面的reStructuredText格式,并使用以下格式返回元组自动完成选项。
def func():
"""
Returns:
:rtype: (int, str)
"""
pass
a, b = func()
这可以成为您寻找的解决方案吗?
PEP 484指定的类型提示是否无效?
Python 3 docs for typing module
from typing import Tuple
def func():
"""
:rtype: Tuple[int, str]
"""
pass
a, b = func()