Pycharm: Auto generate `: type param:` field in docstring

When I create a function with parameters, PyCharm offers me to create a docstring with a field :param param_name: which is pretty good. But I also need to add :type param_name:

So from this:

 def foo(bar, xyz): return bar + xyz 

With the generate docstring option I have (even with Insert 'type' and 'rtype' until the documentation stub is resolved):

 def foo(bar, xyz): """ :param bar: :param xyz: """ return bar + xyz 

And I would like to :

 def foo(bar, xyz): """ :param bar: :type bar: :param xyz: :type xyz: """ return bar + xyz 
+6
source share
4 answers

Per documentation :

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

Following the link:

...

  1. On the Smart Keys page, select the Insert 'type' and 'rtype' checkbox for comment comments .

Once you do this, place the cursor in the parameter name in the definition, activate the Smart Keys function ( Alt + Enter , by default) and select Specify link type in docstring . This inserts the corresponding comment line. Similarly, you can place the cursor in the name of the function / method and select Specify return type in docstring .

+8
source

Just check this box:

Editor - General - Smart Keys - Insert a placeholder type into the documentation comment stub.

Also remember to include this element so that you can use Alt + enter to automatically insert documentation:

Editor - General - Smart Keys - Insert comment on comment

0
source

An answer has already been given to what you asked, but I consider it appropriate to indicate that you can use

 def foo(bar, xyz): """ :param bar_type bar: :param xyz_type xyz: """ return bar + xyz 

Use to specify bar_type and xyz_type variable types. Good tip that you can use | install more than one possible type. Example:

 def foo(bar, xyz): """ :param float|int bar: :param numpy.array xyz: """ return bar + xyz 
0
source

In preference settings:

pycharm auto: parameter type:

0
source

Source: https://habr.com/ru/post/989796/


All Articles