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:

enter image description here

(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:

enter image description here

(3) If I stick to the sign @

and drop the types, I get the parameter descriptions:

enter image description here

(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):

enter image description here

(5) Finally, for completeness, :

instead of @

forcing everything to not be filled:

enter image description here

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).

+3


source to share


3 answers


Copied straight from Pycharm: Auto generate`: type param: `field in docstring :


Per documentation :

If configured , documentation comment stubs can be created with tags type

and rtype

.

Following the link:



...

  1. 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: 
    """

      

+1


source


It works with the latest PyCharm (2016.2 CE) and even some previous patched versions.

it works! (Screenshot)



I asked a similar question and got the answer!

PyCharm and reStructuredText documentation popups (Sphinx)

0


source


Have you checked Settings...- Tools- Python integrated tools- Docstring format? You can choose the parsing style.

You can choose:

  • Usual
  • Epytext
  • ReStructuredText
  • Numpy
  • Google
0


source







All Articles