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
🌐
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.
Discussions

Is this docstring correct ? should 'Args' or 'Parameters', can I avoid have empty line with special character?
Well done for writing docstrings at all, you're in the top 95% of people who ask questions in this sub! The blank line inside it is recommended in a couple of style guides, but if that's not just the reddit code formatting gremlin, you should start the whole docstring on a new line separate to the function header, so automated tools can pick it up. By "valid folder Id" do you mean a file path to a directory, or some specific internal DB thing, like how the DB tables are structured? What are the keys to the dictionaries, the DB table field names? Doc strings aren't really about being concise, but any fine person who takes the trouble to read comments in code will know what DB stands for. And if you added type annotations to the function (especially if you generics: List[dict]), you wouldn't need to repeat those at least inside the docstring More on reddit.com
🌐 r/learnpython
12
1
October 5, 2022
What is the "working" Python docstring style for VS Code tooltips?
I think I see what you mean. It doesn't really answer your question, but here are a couple considerations that can make your life easier in the meantime: I wanted to make the docstrings more legible in the code. I used the extension Highlight to write ugly regexes to match specific characters in a Google-style docstring, to make it more legible, like so . Instead of relying on tooltips, you can rely on another nice feature of VS Code: Peek Definition. It allows you to look to another location in the code in-place. It's a nice way to quickly see what a function does somewhere else in the code. You can bind this operation to a keybind of your liking to do that efficiently. I also recommend using the autoDocstring extension, which works nice. I wrote a custom mustache template to remove types from the Google template, as I rely on the extension sphinx_autodoc_typehints to generate them from my type hints. More on reddit.com
🌐 r/vscode
2
3
March 13, 2020
How do you guys refer to variables in your comments?
I do direction (with backticks) I think, for some languages at least, when you do it like this and generate documentation, the generated docs render it as code. If I’m wrong then I guess its just personal preference More on reddit.com
🌐 r/Python
40
38
December 10, 2022
Python look up functions/class documentation in Atom?

I think you want a little description of what the function does when you are typing.

If that's what you want, there is autocomplete-python.

More on reddit.com
🌐 r/Atom
2
3
February 15, 2016
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.

🌐
Python
peps.python.org › pep-0257
PEP 257 – Docstring Conventions | peps.python.org
The docstring of a script (a stand-alone program) should be usable as its “usage” message, printed when the script is invoked with incorrect or missing arguments (or perhaps with a “-h” option, for “help”). Such a docstring should document the script’s function and command line syntax, environment variables, and files. 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.
🌐
Zero To Mastery
zerotomastery.io › blog › python-docstring
Beginner's Guide to Python Docstrings (With Code Examples) | Zero To Mastery
Docstrings are a step up from comments. Think of them as mini-explanations that stick with your functions, classes, or modules. They live inside your code, but they’re also accessible through Python's help() function, making them perfect for creating formal documentation.
🌐
Sphinx
sphinx-doc.org › en › master › usage › referencing.html
Cross-references — Sphinx documentation
.. function:: install() This function installs a `handler` for every signal known by the `signal` module. See the section `about-signals` for more information. 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`).
🌐
Python-sprints
python-sprints.github.io › pandas › guide › pandas_docstring.html
pandas docstring guide — Python 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.
Find elsewhere
🌐
Dataquest
dataquest.io › home › blog › how to use python docstrings for effective code documentation
Tutorial: Documenting in Python with Docstrings
December 13, 2024 - The Python docstring of this function is enclosed between three double quotes from both sides. As you can see, this string explains what this function does and indicates how we can change its functionality — and what happens if it doesn't ...
🌐
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.
🌐
Quora
quora.com › Why-do-Pythons-docstrings-go-inside-the-function-contrary-to-most-languages-where-Javadoc-goes-above-the-function
Why do Python's docstrings go inside the function, contrary to most languages where Javadoc goes above the function? - Quora
Answer (1 of 4): Because that is the way that the language has been designed. The docstring is defined a non-assigned string literal that exists as the very first item after the def statement. That string literal is stored as mutable attribute on the function (__doc__), and it makes sense for the...
🌐
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.
🌐
Software Testing Help
softwaretestinghelp.com › home › python › python docstring: documenting and introspecting functions
Python Docstring: Documenting And Introspecting Functions
April 1, 2025 - This tutorial explains what is Python Docstring and how to use it to document Python functions with examples. Includes function introspecting.
🌐
CopyProgramming
copyprogramming.com › howto › link-to-class-method-in-python-docstring
Python: Python Docstring: How to Include a Link to a Class Method
March 16, 2023 - Sphinx has various Docstring "roles" designated for distinct objectives, indicated by the :foo: preceding the text enclosed in backticks. The code doc refers to an entire file. ref serves as a cross-reference without any specific criteria. ... Regarding Python code, the "domain" identified ...
🌐
Readthedocs
sphinx-rtd-tutorial.readthedocs.io › en › latest › docstrings.html
Writing docstrings — Sphinx-RTD-Tutorial documentation
If you are using VS code, the Python Docstring extension can be used to auto-generate a docstring snippet once a function/class has been written.
🌐
Sphinx
sphinx-doc.org › en › master › usage › extensions › autodoc.html
sphinx.ext.autodoc – Include documentation from docstrings — Sphinx documentation
def _my_function(my_arg, my_other_arg): """blah blah blah :meta public: """ Added in version 3.1. autodoc considers a variable member does not have any default value if its docstring contains :meta hide-value: in its Info field lists. Example: ... Added in version 3.5. Python has no built-in support for docstrings for module data members or class attributes.
🌐
Python documentation
docs.python.org › 3 › tutorial › controlflow.html
4. More Control Flow Tools — Python 3.14.7 documentation
There are tools which use docstrings to automatically produce online or printed documentation, or to let the user interactively browse through code; it’s good practice to include docstrings in code that you write, so make a habit of it. The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names.
🌐
Burke
kevin.burke.dev › kevin › sphinx-interlinks
How to create rich links in your Sphinx documentation | Kevin Burke
December 28, 2013 - Kevin, further to linking to one set of docs from another, I followed your `intersphinx_mapping` syntax above. My version looks like this: ““ intersphinx_mapping = { ‘leapyear-python’: (‘https://leapyear-python-docs.readthedocs-hosted.com/en/latest’, None), ‘python’: (‘http://docs.python.org/3’, None), } “` Then in my top-level `index.rst` file I effected this change: “` .. toctree:: User Guide Installation Guide POC Setup Checklist LeapYear Python Client Reference “`
🌐
Lsst
developer.lsst.io › v › u-krughoff-fix-sdss-pointer › docs › py_docs.html
Documenting Python APIs with Docstrings — LSST DM Developer Guide u-krughoff-fix-sdss-pointer 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.
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › development › contributing_docstring.html
pandas docstring guide — pandas 3.0.1 documentation
After the header, we will add a line for each related method or function, followed by a space, a colon, another space, and a short description that illustrates what this method or function does, why is it relevant in this context, and what the key differences are between the documented function and the one being referenced.