The solution that works for Sphinx is to prefix the reference with ~.

Per the Sphinx documentation on Cross-referencing Syntax,

If you prefix the content with ~, the link text will only be the last component of the target. For example, :py:meth:`~Queue.Queue.get` will refer to Queue.Queue.get but only display get as the link text.

So the answer is:

class MyClass():
    def foo(self):
        print 'foo'
    def bar(self):
        """This method does the same as :func:`~mymodule.MyClass.foo`"""
        print 'foo'

This results in an HTML looking like this : This method does the same as foo(), and foo() is a link.

However, note that this may not display in Spyder as a link.

Answer from saroele on Stack Overflow
🌐
GitHub
github.com › mkdocstrings › python › issues › 166
feature: extension(?): relative cross-references in docstrings, but resolved by the handler/extractor · Issue #166 · mkdocstrings/python
May 2, 2024 - I imagine that this is unambiguous enough to have a very low false-positive rate, so it should be “relatively safe“ to treat every such equal-text-and-target link which is also a valid Python identifier as a cross-reference to resolve this way. From my understanding of the architecture of mkdocs + mkdocs-autorefs + mkdocstrings-python, I believe there are two parts to this proposal: Griffe (or a Griffe extension) should check if the current docstring contains a Markdown cross-reference of the aforementioned type.
Author: mkdocstrings
🌐
CKAN
docs.ckan.org › en › ckan-2.2.3 › python-coding-standards.html
Python coding standards — CKAN 2.2.3 documentation
We use '''triple single quotes''' around docstrings, not """triple double quotes""" (put triple single quotes around one-line docstrings as well as multi-line ones, it makes them easier to expand later) We use Sphinx domain object cross-references to cross-reference to other code objects (see below) We use Sphinx directives for documenting parameters, exceptions and return values (see below) If you want to refer to another Python or JavaScript module, function or class etc.
🌐
GitHub
github.com › sphinx-doc › sphinx › issues › 6211
Docstring implicit inheritance can render cross-reference targets ambiguous. · Issue #6211 · sphinx-doc/sphinx
March 27, 2019 - Build the docs with themodule.py in the PYTHONPATH (PYTHONPATH=. make html) -- things work fine; in particular the doc of A.dothis correctly links to A.dothat. Now let's say someone adds (in the same module) a subclass of A that overrides dothis, but doesn't bother with a docstring: ... /tmp/testdocs/themodule.py:docstring of themodule.B.dothis:1: WARNING: more than one target found for cross-reference 'dothat': themodule.A.dothat, themodule.Unrelated.dothat
Author: sphinx-doc
🌐
Mkdocstrings
mkdocstrings.github.io › usage
Usage - mkdocstrings
Python developers coming from Sphinx might know about its intersphinx extension, that allows to cross-reference items between several projects.
🌐
Mkdocstrings
mkdocstrings.github.io › python
Overview - mkdocstrings-python
Thanks to mkdocstrings cross-reference ability, you can reference other objects within your docstrings, with the classic Markdown syntax: [this object][package.module.object] or directly with [package.module.object][] Source code display: mkdocstrings can add a collapsible div containing the ...
🌐
SymPy
docs.sympy.org › latest › contributing › docstring.html
Docstrings Style Guide - SymPy 1.14.0 documentation
First namespace is set to particular submodule (file) with .. module:: directive, then docstrings are imported with .. autoclass:: or .. autofunction:: relative to that submodule (file). Other methods are either cumbersome to use (using full paths for all objects) or break something (importing relative to main module using .. module:: sympy.geometry breaks viewcode Sphinx extension). All files in doc/src/modules/ should use this format. Any text that references another SymPy function should be formatted so that a cross-reference link to that function’s documentation is created automatically.
🌐
Sphinx
sphinx-doc.org › en › master › usage › referencing.html
Cross-references — Sphinx documentation
there could be references to a glossary term (usually :term:`handler`), a Python module (usually :py:mod:`signal` or :mod:`signal`) and a section (usually :ref:`about-signals`). The any role also works together with the intersphinx extension: when no local cross-reference is found, all object types of intersphinx inventories are also searched.
Find elsewhere
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-22175 › Not-able-to-reference-other-functions-in-my-docstrings-with-a-link
Not able to reference other functions in my docstrings with ...
Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions.
🌐
Mkdocstrings
mkdocstrings.github.io › python › usage › configuration › docstrings
Docstrings - mkdocstrings-python
For example, to cross-reference the current object's name member, you can write [link to name attribute][.name]. The "current object" is the object containing the docstring being rendered.
🌐
Readthedocs
ikerdocs-sphinx.readthedocs.io › extras › crossref.html
Cross referencing Python objects — Sphinx documentation
E.g. if Python is the default domain :py:meth:`~Queue.Queue.get` is equivalent to :meth:`~Queue.Queue.get`. Note · To be able to cross reference object from different projects, take a look at linking to other projects. Before starting · Getting started · reST and Sphinx markup constructs · Documenting your project · Extras · Docstrings ·
🌐
CSDN
devpress.csdn.net › python › 63044eb3c67703293080ab85.html
How would I cross-reference a function generated by autodoc in Sphinx?_python_Mangs-Python
August 23, 2022 - You don't need to add labels. In order to refer to a Python class, method, or other documented object, use the markup provided by the Python domain. For example, the following defines a cross-reference to the mymethod method:
🌐
Matplotlib
matplotlib.org › stable › devel › MEP › MEP10.html
MEP10: Docstring consistency — Matplotlib 3.8.0 documentation
Manually go through all of the docstrings and update them to the new format and conventions. Updating the cross references (from `:func:`myfunc` to `func`) may be able to be semi-automated.
🌐
GitHub
github.com › mkdocstrings › mkdocstrings › issues › 226
Lost cross-references from normal docs to python docstrings? · Issue #226 · mkdocstrings/mkdocstrings
February 8, 2021 - WARNING - reference/cli.md: Could not find cross-reference target '[answers_file]' WARNING - reference/cli.md: Could not find cross-reference target '[exclude]' WARNING - reference/cli.md: Could not find cross-reference target '[vcs_ref]' WARNING - reference/cli.md: Could not find cross-reference target '[pretend]' WARNING - reference/cli.md: Could not find cross-reference target '[force]' WARNING - reference/cli.md: Could not find cross-reference target '[skip_if_exists]' WARNING - reference/cli.md: Could not find cross-reference target '[use_prereleases]' WARNING - reference/cli.md: Could no
Author: mkdocstrings
🌐
Softwareheritage
docs.softwareheritage.org › devel › contributing › sphinx.html
Sphinx gotchas — Software Heritage documentation
Note that you can (and should) omit the <code>:py:</code> prefix, as Python is the default domain. Note also that when building Sphinx documentation for individual Software Heritage modules in isolation, cross-references to other modules will not be resolvable. But they will be resolvable when building the unified documentation from swh-docs · See the list of docstring sections supported by Napoleon.
🌐
DeepDocs
deepdocs.dev › home › 8 practical python docstring examples & patterns
8 Practical Python Docstring Examples & Patterns | DeepDocs
November 25, 2025 - This visual separation makes dense docstrings highly readable. Detailed Parameter Descriptions: Each parameter is defined with its name, type, and description on separate lines, allowing for more extensive explanations. Contextual Cross-Referencing: The See Also section is a powerful feature for building an interconnected documentation system, guiding users to related functions.
Top answer
1 of 1
5

I want to link to other methods / functions / classes from some of the docstrings, but I cannot figure out how to do this.

You're correct that the reStructuredText documentation does not cover this, because it's not a feature of reStructuredText.

Likely you are (explicitly, or implicitly via some tool) using the Sphinx system – a superset of Docutils – to allow (among many other features) references between different docstrings.

Sphinx defines several Docstring “roles” (the :foo: before the backtick-quoted text) for different purposes:

  • doc, a reference to an entire document.
  • ref, an arbitrary cross-reference.
  • … many others.

For specifically Python code, the “domain” py has its own specific set of roles for Python code docstrings:

  • :py:mod:

    Reference a module; a dotted name may be used. This should also be used for package names.

  • :py:func:

    Reference a Python function; dotted names may be used. The role text needs not include trailing parentheses to enhance readability; they will be added automatically by Sphinx if the add_function_parentheses config value is True (the default).

  • :py:data:

    Reference a module-level variable.

  • :py:const:

    Reference a “defined” constant. This may be a Python variable that is not intended to be changed.

  • :py:class:

    Reference a class; a dotted name may be used.

  • :py:meth:

    Reference a method of an object. The role text can include the type name and the method name; if it occurs within the description of a type, the type name can be omitted. A dotted name may be used.

  • :py:attr:

    Reference a data attribute of an object.

  • :py:exc:

    Reference an exception. A dotted name may be used.

  • :py:obj:

    Reference an object of unspecified type.

🌐
JetBrains
youtrack.jetbrains.com › issue › PY-27635 › Treat-Sphinx-Python-domain-references-in-docstrings-as-first-class-citizens
Treat Sphinx Python domain references in docstrings as first-class citizens : PY-27635
Wait, 6 years have passed and PyCharm can't............. cross-reference functions on documentation? I think this is available on PHPStorm since forever! Besides the usual +1 baffling comment, I'm actually here to point that this is directly present on PEP 287 - reStructuredText Docstring Format, even without the :func: prefix: Markup that isolates a Python identifier: interpreted text.