如何在Google风格的Pydoc for Pycharm中表示返回类型元组?

问题描述 投票:11回答:2

在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接收返回类型?

python pycharm pydoc
2个回答
0
投票

来自sphinxcontrib的doc页面

Returns部分支持任何reStructuredText格式, 包括文字块::

        {
            'param1': param1,
            'param2': param2
        }

Documentation

这表示Google风格支持里面的reStructuredText格式,并使用以下格式返回元组自动完成选项。

def func():
    """

    Returns:
        :rtype: (int, str)

    """
    pass

a, b = func()

这可以成为您寻找的解决方案吗?


0
投票

PEP 484指定的类型提示是否无效?

Python 3 docs for typing module

Python PEP 484

from typing import Tuple

def func():
    """

    :rtype: Tuple[int, str]
    """
    pass

a, b = func()
© www.soinside.com 2019 - 2024. All rights reserved.