Skip to content Skip to sidebar Skip to footer

Should I Document Parameters For Similar Function Signatures?

I have some helper functions that, except for the first argument, take the same arguments as the core function. The parameters are thoroughly documented in the core function. Shoul

Solution 1:

The best, and easiest, way to do this is using Python Sphinx docstring sections from the sphinx.ext.napoleon extension.

Only arguments unique to the helper function need to be explicitly documented, you can remit with a cross-reference to the function/method defining the shared parameters. The Google style guide for Python advises the same reasoning for overloading inherited methods from a base class :

A method that overrides a method from a base class may have a simple docstring sending the reader to its overridden method’s docstring, such as """See base class.""". The rationale is that there is no need to repeat in many places documentation that is already present in the base method’s docstring. However, if the overriding method’s behavior is substantially different from the overridden method, or details need to be provided (e.g., documenting additional side effects), a docstring with at least those differences is required on the overriding method.

  • Args:

    List each parameter by name. A description should follow the name, and be separated by a colon and a space.

The following example:

defcore(param0, param1=3, param2=8):
    """Core function with thorough documentation.

    Parameters
    ----------
    param0 : ndarray
        Description.
    param1 : int
        Long description.
    param2 : int
        Long description.

    Returns
    -------
    param_out : ndarray
        Long description

    """passdefhelper(param3, param1=3, param2=8):
    """Remaining

    Parameters
    ----------
    param3 : int
        Description.
    Other Parameters
        A short string remitting reader to :py:func:`core` function.
    See Also
        A short string remitting reader to :py:func:`core` function.
    Note
        A short string remitting reader to :py:func:`core` function.
    """pass

Would give this result:

enter image description here

Post a Comment for "Should I Document Parameters For Similar Function Signatures?"