Documenting `tuple` return type in a function docstring for PyCharm type hinting

后端 未结 1 1247
礼貌的吻别
礼貌的吻别 2021-01-01 08:42

How can I document that a function returns a tuple in such a way that PyCharm will be able to use it for type hinting?

Contrived example:



        
相关标签:
1条回答
  • 2021-01-01 09:30

    I contacted PyCharm support, and this is what they said:

    For tuple please use (<type_1>, <type_2>, <type_3>, e t.c.) syntax.

    E.g.:

    """
    :rtype: (string, int, int)
    """
    

    This is confirmed in PyCharm's documentation:

    Type Syntax

    Type syntax in Python docstrings is not defined by any standard. Thus, PyCharm suggests the following notation:

    ...

    • (Foo, Bar) # Tuple of Foo and Bar
    0 讨论(0)
提交回复
热议问题