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
🌐
Python
peps.python.org › pep-0257
PEP 257 – Docstring Conventions | peps.python.org
Usage messages can be fairly elaborate (several screens full) and should be sufficient for a new user to use the command properly, as well as a complete quick reference to all options and arguments for the sophisticated user. The docstring for a module should generally list the classes, exceptions and functions (and any other objects) that are exported by the module, with a one-line summary of each.
🌐
Programiz
programiz.com › python-programming › docstrings
Python Docstrings (With Examples)
| | Parameters | ---------- | additional : str, optional | More info to be displayed (default is None) | | Returns | ------- | None | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) Here, we can see that the help() function retrieves the docstrings of the Person class along with the methods associated with that class. The docstrings for Python script should document the script's functions and command-line syntax as a usable message.
🌐
DataCamp
datacamp.com › tutorial › docstrings-python
Python Docstrings Tutorial : Examples & Format for Pydoc, Numpy, Sphinx Doc Strings | DataCamp
February 14, 2025 - For example, you could access the docstring for a function using my_function.__doc__or the docstring for a class using MyClass.__doc__. No, docstrings are not required in Python. However, they are part of the best practices for documenting your code. You can access them at runtime using the __doc__ attribute, which can be helpful for debugging and testing, and they can also be used by other tools, such as documentation generators, to create user guides and API references automatically.
🌐
André Luiz Pires Guedes
inf.ufpr.br › cursos › ci067 › Docs › doxygen › examples › docstring › html › classdocstring_1_1PyClass.html
Python: docstring.PyClass Class Reference
List of all members. Public Member Functions def __init__ def PyMethod Detailed Description Documentation for a class. More details. Member Function Documentation def docstring.PyClass.__init__ ( self ) · def docstring.PyClass.PyMethod ( self )
🌐
Doxygen
doxygen.nl › manual › examples › docstring › html › classdocstring_1_1_py_class.html
Python: docstring.PyClass Class Reference
docstring.PyClass Class Reference · Documentation for a class. More details. The constructor. Documentation for a method. The documentation for this class was generated from the following file: docstring.py · docstring · PyClass ·
🌐
Noirlab
datalab.noirlab.edu › docs › manual › DevGuide › DocumentingPythonAPIswithDocstrings › DocumentingPythonAPIswithDocstrings.html
3.2. Documenting Python APIs with Docstrings — Data Lab documentation
References ---------- .. [1] Z. Ivezic and the LSST Science Collaboration. 2011, LSST Science Requirements Document, LPM-17, URL https://ls.st/LPM-17 """ In many classes, public attributes are set in the __init__ method. The best way to document these public attributes is by declaring the attribute at the class level and including a docstring with that declaration:
🌐
CKAN
docs.ckan.org › en › ckan-2.2.3 › python-coding-standards.html
Python coding standards — CKAN 2.2.3 documentation
Use :raises: to document exceptions raised by public functions. The docstring should say what type of exception is raised and under what conditions. Use :py:class: to reference exception types.
🌐
Mkdocstrings
mkdocstrings.github.io › python › usage › configuration › docstrings
Docstrings - mkdocstrings-python
plugins: - mkdocstrings: handlers: python: options: docstring_options: ignore_init_summary: false trim_doctest_flags: true ... class PrintOK: """Class docstring.""" def __init__(self): """Initialize the instance.
Find elsewhere
🌐
Lsst
developer.lsst.io › python › numpydoc.html
Documenting Python APIs with docstrings — LSST DM Developer Guide main documentation
References ---------- .. [1] Z. Ivezic and the LSST Science Collaboration. 2011, LSST Science Requirements Document, LPM-17, URL https://ls.st/LPM-17 """ In many classes, public attributes are set in the __init__ method. The best way to document these public attributes is by declaring the attribute at the class level and including a docstring with that declaration:
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-docstrings
Python Docstrings - GeeksforGeeks
September 19, 2025 - Docstrings (""" """): Special strings placed below definitions to document modules, classes or functions. Unlike comments, they can be accessed using __doc__ or help(). Note: Docstrings are actually strings too, but Python treats them specially ...
🌐
Pandas
pandas.pydata.org › docs › development › contributing_docstring.html
pandas docstring guide — pandas 3.0.6 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
Attributes: msg (str): Human readable string describing the exception. code (int): Exception error code. """ def __init__(self, msg, code): self.msg = msg self.code = code class ExampleClass(object): """The summary line for a class docstring should fit on one line.
🌐
Readthedocs
pydoctor.readthedocs.io › en › latest › codedoc.html
How to Document Your Code — pydoctor documentation
CONST = 123 """This docstring describes a module level constant.""" class C: cvar = None """This docstring describes a class variable.""" def __init__(self): self.ivar = [];"It can also be used inline." Attribute docstrings are not part of the Python language itself (PEP 224 was rejected), ...
Top answer
1 of 2
11

Yes just drop the methods section from the class docstring. I've never ever seen something like that used.(It is used in few places in the standard library.)  The class docstring needs to just describe the class and the docstring of individual methods then handle describing themselves.

Also the wording in the PEP to me means that the class docstring "should" list the public methods, but not describe them in any other way.(This is also how the above standard library example does it.)  But as said, I would never even do that, since the code speaks for itself and that kind of listing is bound to get out-of-date.

Final note: I personally prefer to use the Google docstring style, because to me it's the clearest and cleanest.

2 of 2
2

example:

class Animal:
    """
    A class used to represent an Animal

    ...

Attributes
----------
says_str : str
    a formatted string to print out what the animal says
name : str
    the name of the animal
sound : str
    the sound that the animal makes
num_legs : int
    the number of legs the animal has (default 4)

Methods
-------
says(sound=None)
    Prints the animals name and what sound it makes
"""

says_str = "A {name} says {sound}"

def __init__(self, name, sound, num_legs=4):
    """
    Parameters
    ----------
    name : str
        The name of the animal
    sound : str
        The sound the animal makes
    num_legs : int, optional
        The number of legs the animal (default is 4)
    """

    self.name = name
    self.sound = sound
    self.num_legs = num_legs

def says(self, sound=None):
    """Prints what the animals name is and what sound it makes.

    If the argument `sound` isn't passed in, the default Animal
    sound is used.

    Parameters
    ----------
    sound : str, optional
        The sound the animal makes (default is None)

    Raises
    ------
    NotImplementedError
        If no sound is set for the animal or passed in as a
        parameter.
    """

    if self.sound is None and sound is None:
        raise NotImplementedError("Silent Animals are not supported!")

    out_sound = self.sound if sound is None else sound
    print(self.says_str.format(name=self.name, sound=out_sound))

Yep, listing methods in the class docstring, then each method again documented, according to this standard. I reccomend using sphinx, though: https://www.sphinx-doc.org/en/master/contents.html

🌐
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.
🌐
Linux find Examples
queirozf.com › entries › python-docstrings-reference-examples
Python Docstrings: Reference & Examples
September 1, 2020 - $ python doctest-example.py -v Trying: func(1,2) Expecting: True ok Trying: func(1,1) Expecting: Traceback (most recent call last): ... ValueError: arg1 must not be equal to arg2 ok 1 items had no tests: __main__ 1 items passed all tests: 2 tests in __main__.func 2 tests in 2 items.
🌐
Lukasatkinson
lukasatkinson.de › dump › 2023-08-25-python-docstrings-sphinx
Python docstrings and Sphinx | Lukas Atkinson
August 25, 2023 - But when documenting Python code, this is not a good idea. By separating your code from your reference docs in a separate document, it is harder to keep them in sync. It also duplicates any effort that goes into the docstrings. Luckily, the sphinx.ext.autodoc extension exists. You can now plonk an autoclass or automodule directive into your documentation, and Sphinx will work its magic to fill in all nested classes and methods from the docstrings.
🌐
Real Python
realpython.com › how-to-write-docstrings-in-python
How to Write Docstrings in Python – Real Python
August 25, 2025 - In this section, you’ll explore best practices for writing docstrings across three important parts of most Python codebases: modules, functions, and classes. When you write docstrings for modules, the goal is to provide a high-level summary of what the program does. This appears at the top of your Python file and serves as an overview of its contents. Here, you’ll add a brief description of the module’s purpose and a list of its components. You could also add references to related modules or examples of usage.