In python 3.5 Python added type hinting. Before Python 3.5 existed, there was an open conversation around how to type hint, and it was done in comments. PyCharm supports type hinting in either. I'd recommend doing it the python way for a couple reasons, but it's up to you.

"""These should work"""
from Typing import Tuple

class Foo:
    pass

def foo(a: int, b: float, c: Foo) -> Tuple[int, float, Foo]:
    return a, b, c

def bar(a, b, c) -> Tuple[int, float, Foo]:
    return a, b, c

def that(a, b, c):
    """
    :rtype: Tuple[int, float, Foo]
    """
    return a, b, c

def thing(a, b, c):
    """
    :rtype: (int, float, Foo)
    """
    return a, b, c
"""This should fail because Tuple is not imported, but no warning"""
def that(a, b, c):
    """ 
    :rtype: Tuple[int, float, Foo]
    """
    return a, b, c

"""
This only partially works because 'Foo' isn't in scope. 
This can easily happen if someone refactored the name of 'Foo', 
but the comments wouldn't be updated.
"""
def thing(a, b, c):
    """
    :rtype: (int, float, Foo)
    """
    return a, b, c

def documentation_nightmare(a, b, c):
   """ ​
   There are no checks, and everything seems fine, but the documentation is all wrong and hard to maintain. 
   :param a: A
   :type a: float
   :param b: B
   :type b: Bar
   :param c: C
   :type c: int
   ​:rtype: Tuple[int, float, Foo]
   ​"""
   ​return a, b, c

The main pro of the Python way is.. your code will start to give you type hints and show warnings if you have the wrong types hooked up. If your whole code base is typed then you can run checks to make sure everything is hooked up right. Some people like this, some people don't.

Note, I have done documentation_nightmare before and I hated it. Now I do it with full real typing, and it saves me more time than it costs me, but many people dislike it.

From this SO post:

The complete list of field name can be found here

  • param, parameter, arg, argument, key, keyword: Description of a parameter.
  • type: Type of a parameter. Creates a link if possible.
  • raises, raise, except, exception: That (and when) a specific exception is raised.
  • var, ivar, cvar: Description of a variable.
  • vartype : Type of a variable. Creates a link if possible.
  • returns, return: Description of the return value.
  • rtype: Return type. Creates a link if possible.
  • meta: Add metadata to description of the python object. The metadata will not be shown on output document. For example, :meta private: indicates the python object is private member. It is used in sphinx.ext.autodoc for filtering members.
Answer from nanotek on Stack Overflow
🌐
GitHub
github.com › sphinx-doc › sphinx › issues › 9119
Using multiple return values in Google-style docstrings · Issue #9119 · sphinx-doc/sphinx
April 20, 2021 - There are two related StackOverflow questions ([1], [2]), where some users recommend using a docstring in the following style (version 3): def foo(a, b): """Function Args: a (float): First number b (float): Second number Returns: tuple containing - result_sum (float): Sum of numbers - result_prod (float): Product of numbers """ result_sum = a + b result_prod = a * b return result_sum, result_prod
Author: sphinx-doc
Top answer
1 of 1
2

In python 3.5 Python added type hinting. Before Python 3.5 existed, there was an open conversation around how to type hint, and it was done in comments. PyCharm supports type hinting in either. I'd recommend doing it the python way for a couple reasons, but it's up to you.

"""These should work"""
from Typing import Tuple

class Foo:
    pass

def foo(a: int, b: float, c: Foo) -> Tuple[int, float, Foo]:
    return a, b, c

def bar(a, b, c) -> Tuple[int, float, Foo]:
    return a, b, c

def that(a, b, c):
    """
    :rtype: Tuple[int, float, Foo]
    """
    return a, b, c

def thing(a, b, c):
    """
    :rtype: (int, float, Foo)
    """
    return a, b, c
"""This should fail because Tuple is not imported, but no warning"""
def that(a, b, c):
    """ 
    :rtype: Tuple[int, float, Foo]
    """
    return a, b, c

"""
This only partially works because 'Foo' isn't in scope. 
This can easily happen if someone refactored the name of 'Foo', 
but the comments wouldn't be updated.
"""
def thing(a, b, c):
    """
    :rtype: (int, float, Foo)
    """
    return a, b, c

def documentation_nightmare(a, b, c):
   """ ​
   There are no checks, and everything seems fine, but the documentation is all wrong and hard to maintain. 
   :param a: A
   :type a: float
   :param b: B
   :type b: Bar
   :param c: C
   :type c: int
   ​:rtype: Tuple[int, float, Foo]
   ​"""
   ​return a, b, c

The main pro of the Python way is.. your code will start to give you type hints and show warnings if you have the wrong types hooked up. If your whole code base is typed then you can run checks to make sure everything is hooked up right. Some people like this, some people don't.

Note, I have done documentation_nightmare before and I hated it. Now I do it with full real typing, and it saves me more time than it costs me, but many people dislike it.

From this SO post:

The complete list of field name can be found here

  • param, parameter, arg, argument, key, keyword: Description of a parameter.
  • type: Type of a parameter. Creates a link if possible.
  • raises, raise, except, exception: That (and when) a specific exception is raised.
  • var, ivar, cvar: Description of a variable.
  • vartype : Type of a variable. Creates a link if possible.
  • returns, return: Description of the return value.
  • rtype: Return type. Creates a link if possible.
  • meta: Add metadata to description of the python object. The metadata will not be shown on output document. For example, :meta private: indicates the python object is private member. It is used in sphinx.ext.autodoc for filtering members.
🌐
Stanford
web.stanford.edu › class › archive › cs › cs106a › cs106a.1202 › handouts › py-tuple.html
Stanford
1. The function doc string must state the size and content-types of the returned tuple. There's no way the caller code can be written correctly without this information. 2. All paths should return a tuple of that same length, even if it is (None, None), so that standard looking calling code ...
🌐
GitHub
github.com › mkdocstrings › mkdocstrings › issues › 301
Document multiple return values · Issue #301 · mkdocstrings/mkdocstrings
July 27, 2021 - Proposed Solution For functions with multiple return values, infer type hinting when possible and add support for position-specific variable descriptions. For the following example: def foo() -> tuple[int, float]: """ Returns: First return value. Second return value.
Author: mkdocstrings
🌐
Doruk Kilitcioglu
dorukkilitcioglu.com › 2018 › 08 › 18 › python-better-docstring.html
A case for better Python docstrings - Doruk Kilitcioglu
August 18, 2018 - All the explanations are on a new ... lines and different arguments, making the docstring look clean and visually appealing. For the high level tuples which are the only input or the output for a function, like the return value above, you can use a spread out notation similar ...
🌐
Python-sprints
python-sprints.github.io › pandas › guide › pandas_docstring.html
pandas docstring guide — Python documentation
The documentation of the return is also similar to the parameters. But in this case, no name will be provided, unless the method returns or yields more than one value (a tuple of values).
🌐
CSDN
devpress.csdn.net › python › 62fd8ccac677032930803e66.html
Documenting `tuple` return type in a function docstring for PyCharm type hinting_python_Mangs-Python
August 18, 2022 - :rtype:??? """ ... magic happens here ... return customer_obj.fullname, customer_obj.status #, etc. I contacted PyCharm support, and this is what they said: For tuple please use (<type_1>, <type_2>, <type_3>, e t.c.) syntax. ... Type syntax in Python docstrings is not defined by any standard.
Find elsewhere
🌐
Bomberbot
bomberbot.com › python › python-return-multiple-values-how-to-return-a-tuple-list-or-dictionary
Python Return Multiple Values – How to Return a Tuple, List, or Dictionary - Bomberbot
Document the return type in your function‘s docstring to make the interface clear · Remember, the goal is to write code that is clear, concise, and easy to maintain. Choose the data structure that best fits your needs and makes your code more readable for yourself and other developers. In this guide, we‘ve explored the various ways you can return multiple values from a Python function using tuples...
🌐
GitHub
github.com › mkdocstrings › griffe › issues › 263
bug: Google docstrings: no support for non-multiple or non-named values in Yields section · Issue #263 · mkdocstrings/griffe
May 2, 2024 - Note: The Google style guide, at least as of version 8487c08, treats "Yields:" and "Returns:" identically and requires them to document a tuple of returned values as a tuple, explicitly forbidding the numpy-style named tuple return values. ... """Test "Yields:" sections in Google-style docstrings.""" from __future__ import annotations from collections.abc import Iterator def return_one() -> str: """XXX Returns: Returns one item.
Author: mkdocstrings
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-25752
Type hinting on a returning tuple object with custom class
January 11, 2023 - Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions.
🌐
Google
google.github.io › styleguide › pyguide.html
Google Style Guides | Style guides for Google-originated open-source projects
Instead, describe such a return value as: “Returns: A tuple (mat_a, mat_b), where mat_a is …, and …”. The auxiliary names in the docstring need not necessarily correspond to any internal names used in the function body (as those are not part of the API).
🌐
Python
docs.python.org › 3 › c-api › tuple.html
Tuple Objects — Python 3.14.7 documentation
Pointer to docstring for the type or NULL to omit. ... Pointer to NULL-terminated array with field names of the new type. ... Number of fields visible to the Python side (if used as tuple).
🌐
GitHub
github.com › sphinx-doc › sphinx › issues › 3355
Unable to properly format numpy argument for tuple. Guidance requested. · Issue #3355 · sphinx-doc/sphinx
January 19, 2017 - I seem to be unable to get a tuple defined in the Arguments block of the docstring using numpy style docstrings with Napoleon. (I did not try using Google style). I have tried a variety of differen...
Author: sphinx-doc
🌐
Mit
drake.mit.edu › styleguide › pyguide.html
Google Python Style Guide for Drake
Instead, describe such a return value as: “Returns: A tuple (mat_a, mat_b), where mat_a is …, and …”. The auxiliary names in the docstring need not necessarily correspond to any internal names used in the function body (as those are not part of the API).
🌐
Mkdocstrings
mkdocstrings.github.io › griffe › reference › docstrings
Docstring parsers - Griffe
They should be used only in functions docstrings. Documented items can be given a name when it makes sense. import random def foo() -> int: """Foo. Returns: A random integer. """ return random.randint(0, 100) Type annotations are fetched from the function return annotation. If your function returns tuples of values, you can document each item of the tuple separately, and the type annotation will be fetched accordingly: