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
🌐
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.
🌐
DataCamp
datacamp.com › tutorial › docstrings-python
Python Docstrings Tutorial : Examples & Format for Pydoc, Numpy, Sphinx Doc Strings | DataCamp
February 14, 2025 - Although both triple-single and triple-double quotes work, the standard convention in Python is to use triple-double quotes ("""). ... def square(a): """Returns the square of the given number.""" return a ** 2 # Corrected exponentiation # Accessing the docstring print(square.__doc__) ... Returns the square of the given number. You can also retrieve this documentation using Python's help() function:
🌐
Lsst
developer.lsst.io › python › numpydoc.html
Documenting Python APIs with docstrings — LSST DM Developer Guide main documentation
Use the ‘See Also’ section to link to related APIs that the user may not be aware of, or may not easily discover from other parts of the docstring. Here are some good uses of the ‘See Also’ section: If a function wraps another function, you may want to reference the lower-level function.
🌐
Burke
kevin.burke.dev › kevin › sphinx-interlinks
How to create rich links in your Sphinx documentation | Kevin Burke
December 28, 2013 - # Add the "intersphinx" extension extensions = [ 'sphinx.ext.intersphinx', ] # Add mappings intersphinx_mapping = { 'urllib3': ('http://urllib3.readthedocs.org/en/latest', None), 'python': ('http://docs.python.org/3', None), } You can then link to other projects' documentation and then reference it the same way you do your own projects, and Sphinx will magically make everything work.
🌐
Python
peps.python.org › pep-0257
PEP 257 – Docstring Conventions | peps.python.org
This makes it easy to later expand it. The closing quotes are on the same line as the opening quotes. This looks better for one-liners. There’s no blank line either before or after the docstring. The docstring is a phrase ending in a period. It prescribes the function or method’s effect as a command (“Do this”, “Return that”), not as a description; e.g.
🌐
Programiz
programiz.com › python-programming › docstrings
Python Docstrings (With Examples)
Python docstrings are the string literals that appear right after the definition of a function, method, class, or module. Let's take an example. def square(n): '''Take a number n and return the square of n.''' return n**2 ... Inside the triple quotation marks is the docstring of the function ...
Find elsewhere
🌐
Pandas
pandas.pydata.org › docs › development › contributing_docstring.html
pandas docstring guide — pandas 3.0.5 documentation
A Python docstring is a string used to document a Python module, class, function or method, so programmers can understand what it does without having to read the details of the implementation.
🌐
Readthedocs
sphinxcontrib-napoleon.readthedocs.io › en › latest › example_google.html
Example Google Style Python Docstrings — napoleon 0.7 documentation
Todo: * For module TODOs * You have to also use ``sphinx.ext.todo`` extension .. _Google Python Style Guide: http://google.github.io/styleguide/pyguide.html """ module_level_variable1 = 12345 module_level_variable2 = 98765 """int: Module level variable documented inline. The docstring may span multiple lines. The type may optionally be specified on the first line, separated by a colon. """ def function_with_types_in_docstring(param1, param2): """Example function with types documented in the docstring.
🌐
Linux find Examples
queirozf.com › entries › python-docstrings-reference-examples
Python Docstrings: Reference & Examples
September 1, 2020 - Extended description of function. :param int arg1: Description of arg1. :param str arg2: Description of arg2. :raise: ValueError if arg1 is equal to arg2 :return: Description of return value :rtype: bool :example: >>> a=1 >>> b=2 >>> func(a,b) True """ if arg1 == arg2: raise ValueError('arg1 must not be equal to arg2') return True · Uses more horizontal space (compared with numpy-style) Better for short and simple docstrings.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-docstrings
Python Docstrings - GeeksforGeeks
September 19, 2025 - Example 2: This function shows how to use triple double quotes for docstrings. ... def my_func(): """This is a docstring using triple double quotes.""" return None print(my_func.__doc__) ... This is a docstring using triple double quotes. Google style docstrings follow a specific format and are inspired by Google's documentation style guide. They provide a structured way to document Python code, including parameters, return values and descriptions.
Top answer
1 of 2
10

Different tools access docstrings differently. For example, having a common base class that provides this docstring may be sufficient for some tools but not others.

The most general approach would be to define a functools.wraps() like decorator that copies the docstring of a function, e.g.:

def is_documented_by(original):
  def wrapper(target):
    target.__doc__ = original.__doc__
    return target
  return wrapper

class Waldo:
  @is_documented_by(Foo.getBar)
  def getBar():
    ...

But since this requires executing the Python code, static analyzers like Pylint may not like this. The best solution depends on the tools you are going to use.

2 of 2
0

The approach I've implemented for this was the following:

class Field_Sampler:
    def getBar(self,pos):
        """
        This is the Bar method. 
        It calculates and returns the Bar field effect generated 
        by this source based on `pos`
        """   
        import warnings
        warnings.warn(
            "called getBar method is not implemented in this class,"
            "returning 0", RuntimeWarning)
        return 0


class Foo(Field_Sampler):
    """This is the Foo class Docstring. It is a type of Bar source."""
    def getBar(self,pos): 
        effect = pos + 1 
        return effect

class Waldo(Field_Sampler):
    """This is the Waldo class Docstring. It's also a type of Bar source."""
    def getBar(self,pos):
        effect = pos + 2 
        return effect

class Epsilon(Field_Sampler):
    """[WIP]This is the Epsilon class Docstring. It's also a type of Bar source."""
    pass

A top class has the function prototype with the docstring. Classes inherit this and override the implementation definition of the method. If there's no docstring on the overriden function, then the docstring of the parent is used by most doc interpreters, including Sphinx.

This allowed me to set up the numerous classes while retaining the structure (which included more methods) and stopping static analyzers from freaking out. In the event the method wasn't implemented yet, we have it throw a warning if someone happens to call it.

🌐
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''' ... 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 ...
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-35223 › be-able-to-reference-function-class-in-docstring
be able to reference function/class in docstring : PY-35223
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.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 4334
Support reference-style Markdown links in Docstring rendering · Issue #4334 · microsoft/pylance-release
May 8, 2023 - I am using mkdocstrings to build documentation for my project, but have noticed that when I use Markdown's reference-style links in order to link various functions and classes in my code together. For example, [foo.bar][] should render as a link to the bar object in the foo module. This works great for my documentation site, but means that users of my package who use VS Code's intellisense have a suboptimal experience as the Python extension renders this markdown incorrectly.
Author: microsoft
🌐
Dataquest
dataquest.io › home › blog › how to use python docstrings for effective code documentation
Tutorial: Documenting in Python with Docstrings
December 13, 2024 - I strongly recommend you read it all even though you may not understand all of it. The essential points are as follows: Use triple double quotes to enclose docstrings. Docstring ends with a dot.
🌐
Mkdocstrings
mkdocstrings.github.io › python › usage › configuration › docstrings
Docstrings - mkdocstrings-python
Whether to render the "Functions" or "Methods" section of docstrings. ... """Summary. Functions: foo: Some function. """ def foo(): ... class Class: """Summary. Methods: bar: Some method. """ def bar(self): ... ... Whether to render the "Classes" section of docstrings.
🌐
DEV Community
dev.to › kristenkinnearohlmann › using-the-python-docstring-to-document-functions-49mh
Using The Python Docstring To Document Functions - DEV Community
July 25, 2022 - Here is an example of a function without a docstring - only the function signature, if provided, is displayed: ... Here is an example of function with a docstring - the contextual help displays the text from the docstring as well as the function signature, if any: