Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I use docstrings in PyCharm?

Press Ctrl+Alt+S and go to Editor | General |Smart Keys. Select the Insert type placeholders checkbox in the Smart Keys page of the editor settings. Place the caret at the function name, and press Alt+Enter . In the list of intention actions that opens, choose Insert documentation string stub.

How do I get function documentation in PyCharm?

PyCharm recognizes inline documentation created in accordance with the JavaScript Documentation Tool format. Press Ctrl+Q or choose View | Quick Documentation Lookup on the main menu. In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | General | Code Completion. The Code completion page opens.

How do you display the docstring for a function?

Docstrings are accessible from the doc attribute (__doc__) for any of the Python objects and also with the built-in help() function. An object's docstring is defined by including a string constant as the first statement in the object's definition.

How do I automatically add a docstring in PyCharm?

In the Docstrings section, set the Docstring format to 'reStructuredText' and make sure 'Analyze Python code in doctrings' is selected. If you type the triple quotes to start your docstring and then press Enter, PyCharm will automatically provide a number of relevant sphinx Info Fields for you.


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