Link to a class method of another module in python docstring

I want to add a method reference of one module ( say module_2.py) to another method of another module ( say module_1.py). I want the link to work in Sphinx.

Let's pretend that:

module_1.py

class ABC:
   def foo(self):
      """
     See docstring of module_2.py bar():<link to bar() in module_2.py>
      """
      print("foo")

module_2.py

class XYZ:
    def bar(self):
    """
     This function prints hello.
    """
    print("hello")
+4
source share
1 answer

You can write:

class ABC:
  def foo(self):
    """
    See docstring of :py:meth:`bar() <XYZ.bar>` in :py:mod:`module_2`.
    """
    print("foo")

. Python , :py . meth . . , mod . ``. ( differnet, <>). : :role:`text <logical name>`.

: http://www.sphinx-doc.org/en/stable/domains.html#role-py:meth

+2

Source: https://habr.com/ru/post/1682125/


All Articles