Documenting Python options in docstring using PyCharm
I am having trouble finding a proper way to document a method in Pycharm for getting type hints and parameter descriptions.
The documentation Pycharm offers:
: param "type_name" "param_name": "param_description"
(1) However, when I try to use this, the function definition does not display the parameter description correctly:
(2) If I switch to a signed presenter @
, I get a list of parameters and their types, but I don't get a description of the parameter:
(3) If I stick to the sign @
and drop the types, I get the parameter descriptions:
(4) If I explicitly add @type
for each @param
(which totally blows up the size of the comment block) everything works correctly (but I hate the size of the comment):
(5) Finally, for completeness, :
instead of @
forcing everything to not be filled:
Note that I tried to change the documentation system in Pycharm, but this does not affect how it displays the documentation - it only affects how it automatically blocks the comment block for you.
How can I achieve a documentation close to example (1) that is compact, but does it actually fill out the function definition correctly? I don't want to get hung up on style (4).
source to share
Copied straight from Pycharm: Auto generate`: type param: `field in docstring :
Per documentation :
If configured , documentation comment stubs can be created with tags
type
andrtype
.
Following the link:
...
- On the Smart Keys page , select the Insert 'type' and 'rtype' checkbox for comment comments .
Once you have done that, place your cursor on the parameter name in the definition, activate the Smart Keys feature ( Alt+ Enter, default) and select Specify Link Type in docstring . This inserts the appropriate comment line. Likewise, you can place the cursor on the function / method name and select Specify return type in docstring .
So now, if you type """
after the function declaration, it will automatically create them for you:
def funct(a, b, c):
"""
:param a:
:type a:
:param b:
:type b:
:param c:
:type c:
:return:
:rtype:
"""
source to share