How to automatically refer to parameter type in Doststrings in Sphinx?

For example, I have the following code:

# Solve for coefficients of quadratic approximation
def quad(p, x):
    """Solves for the coefficients of the quadratic approximation of a
    polynomial ``p`` at points ``x``.

    :param :cls:`numpy.polynomial.Polynomial` p:
        The polynomial to be approximated by a quadratic function.
    :param list x:
        The three points along which the quadratic function is to be fitted.
    """

Pay attention to the part where I say . How to make this link directly in the documentation for the class ?:cls:numpy.polynomial.Polynomialnumpy.polynomial.Polynomial

+3
source share
2 answers

You can use intersphinx for this.

  • Add these lines to conf.py:

    extensions = ["sphinx.ext.intersphinx"]        # Or edit existing 'extensions' list
    intersphinx_mapping = {'numpy': ('http://docs.scipy.org/doc/numpy/', None)}
    
  • Use this reST markup in docstring:

     
    :param p: The polynomial to be approximated by a quadratic function.
    :type p: :class:`~numpy:numpy.polynomial.polynomial.Polynomial`
    

This will lead to a hyperlink (with the text "Polynomial") from the documentation of your function quad()to the documentation numpy.polynomial.polynomial.Polynomial.

numpy.polynomial.Polynomial numpy.polynomial.polynomial.Polynomial (. http://docs.scipy.org/doc/numpy/reference/routines.polynomials.classes.html#basics). - , .

, , (~). . http://sphinx-doc.org/domains.html " " Python.

+6

.

"""
...
:param p: The polynomial to be approximated by a quadratic function.
:type p: numpy.polynomial.Polynomial
...
:return: description of return value
:rtype: type of return value
"""
+2

All Articles