29

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.

gak
  • 32,061
  • 28
  • 119
  • 154
  • Also related: https://stackoverflow.com/questions/47445007/pycharm-docstring-code-references-and-docstring-inheritance – Albert Oct 26 '21 at 10:16

2 Answers2

24

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

B.D.
  • 100
  • 4
gak
  • 32,061
  • 28
  • 119
  • 154
21
def die_hard(self):
    """
    Throws a :class:`NakatomiPlazaError`.
    """
    raise NakatomiPlazaError('Yippee ki-yay')

Worked for me.

MrMister
  • 2,456
  • 21
  • 31
  • 5
    I tried this, ctrl-click on the class in the doc-string doesn't go to definition. – Chris2048 Jul 05 '19 at 10:19
  • 2
    This works, but curiously only in the main body of a docstring. For some reason it e.g. doesn't work in a line after `:param name_of_param:` – z33k Feb 18 '21 at 11:51
  • This worked for me in Intellij 2020.3 too – Leroy Mar 09 '21 at 14:09
  • @z33k indeed, this is being tracked at [PY-27635](https://youtrack.jetbrains.com/issue/PY-27635#focus=Comments-27-4916931.0-0). – MrMister Sep 13 '21 at 14:24