Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm docstrings linking to classes

IntelliJ IDEA allows for linking to other methods in Java document comments. This allows me to move the cursor over a symbol and jump to the definition using a keyboard shortcut, as well as holding down ctrl while hovering with the mouse displaying an underline under the symbol which is clickable. For example:

/**   * This is a link to a method {@link #setBalance}   */ 

I am trying to achieve this in Python with PyCharm. I've tried various things from other answers without any luck. Here are some attempts:

def my_func(my_arg):     '''     Convert a S{decimal.Decimal} to an :ref:`int`.      This method imports a module called :mod:``django``.      Sometimes we might call :func:`~utils.error` to raise an {@link Exception}.     ''' 

None of these autocomplete or create a hyperlink.

Could it be that PyCharm simply hasn't implemented this functionality (yet)?

This question is similar to Link to class method in python docstring but the answers don't seem to apply to PyCharm.

like image 995
gak Avatar asked Dec 14 '14 23:12

gak


People also ask

Do classes have docstrings Python?

Python documentation string or commonly known as docstring, is a string literal, and it is used in the class, module, function, or method definition. Docstrings are accessible from the doc attribute (__doc__) for any of the Python objects and also with the built-in help() function.

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.

Can docstrings be assigned to variables?

Yes, you can do that! You can actually 'document' lambdas and variables in a module by attaching docstrings to them.

What should be included in a class docstring?

Class method docstrings should contain the following: A brief description of what the method is and what it's used for. Any arguments (both required and optional) that are passed including keyword arguments. Label any arguments that are considered optional or have a default value.


2 Answers

I contacted support and it turns out it hasn't been implemented.

I have created a feature request on their issue tracker:

https://youtrack.jetbrains.com/issue/PY-14743

Update:

original feature request is marked as a duplicate of

https://youtrack.jetbrains.com/issue/PY-27635

State: In progress

like image 131
gak Avatar answered Oct 11 '22 19:10

gak


def die_hard(self):     """     Throws a :class:`NakatomiPlazaError`.     """     raise NakatomiPlazaError('Yippee ki-yay') 

Worked for me.

like image 31
MrMister Avatar answered Oct 11 '22 21:10

MrMister