Creating docs for dispatched functions using Sphinx

218 Views Asked by At

I am using the multipledispatch package in order to dispatch some functions. I created meaningful docstrings for every function. The code just runs fine.

# md.py

from multipledispatch import dispatch


@dispatch(int, int)
def calc(a: int, b: int) -> int:
    """Adds two integers

    Parameters
    ----------
    a, b : int
        Integer to be added

    Returns
    -------
    int
        Sum of `a` and `b`.
    """
    return a + b


@dispatch(str, str)
def calc(a: str, b: str) -> str:
    """Adds two strings

    Parameters
    ----------
    a, b : str
        Strings to be concatenated

    Returns
    -------
    str
        Concatenated string.
    """
    return f"{a} {b}"


@dispatch(float, str)
def calc(a: float, b: str) -> float:
    """Adds two floats.

    The second float wil be transformed from a string.

    Parameters
    ----------
    a : float
        First summand.
    b : str
        Second summand, will be transformed into flaot.

    Returns
    -------
    float
        Sum of `a` and `b`
    """
    return a + float(b)


def add(a: int, b: int) -> int:
    """Adds two integers

    Parameters
    ----------
    a, b : int
        Integer to be added

    Returns
    -------
    int
        Sum of `a` and `b`.
    """
    return a + b

However, I am struggling when it comes to create HTML documentation using Sphinx. It simply doesn't create the dispatched functions' docs. For functions that are not dispatched (such as add in my example), the docs are correct. Sphinx doesn't throw any error when issuing the make html command.

Here's my md.rst content:

*************
API Reference
*************

.. automodule:: md
    :members:

HTML docs

I'm not sure what really to expect from Sphinx (that is, how should the result look like), but issuing help(calc) in a command line window reveals the following:

help(calc)
Help on Dispatcher in module multipledispatch.dispatcher:
calc = <dispatched calc>
    Multiply dispatched method: calc
    
    Inputs: <int, int>
    -------------------
    Adds two integers
    
        Parameters
        ----------
        a, b : int
            Integer to be added
    
        Returns
        -------
        int
            Sum of `a` and `b`.
    
    Inputs: <str, str>
    -------------------
    Adds two integers
    
        Parameters
        ----------
        a, b : str
            Strings to be concatenated
    
        Returns
        -------
        str
            Concatenated string.
    
    Inputs: <float, str>
    ---------------------
    Adds two floats.
    
        The second float wil be transformed from a string.
    
        Parameters
        ----------
        a : float
            First summand.
        b : str
            Second summand, will be transformed into flaot.
    
        Returns
        -------
        float
            Sum of `a` and `b`

I would be happy if I can get something like this via Sphinx.

0

There are 0 best solutions below