Documenting `tuple` return type in a function docstring for PyCharm type hinting
22,532
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
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
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:
def fetch_abbrev_customer_info(customer_id): """Pulls abbreviated customer data from the database for the Customer with the specified PK value. :type customer_id:int The ID of the Customer record to fetch. :rtype:??? """ ... magic happens here ... return customer_obj.fullname, customer_obj.status #, etc.
-
Jiminion almost 11 years:returns: customer name: his name, customer status: his status, customer's dog's name: usually Fido.
-
RussW almost 11 yearsCouldn't the whole string just be
"""Return (name, status, etc)"""
? Everything else seems a bit redundant. Unless the PK value had something to do with what kind of customer_id the function expects. -
Admin almost 11 yearsUpdated the question text to be a bit less subjective.
-
-
Bodhi over 6 yearsI think this is now broken as of PyCharm 2017.1.5