Tomergt45
Tomergt45

Reputation: 679

Numpydoc how to document the signature of a function as an argument

I have the function

def foo(bar):
    return bar(var1, var2)

where bar is a function that takes two variables named var1 and var2 and returns an str obj, what is the proper numpydocs way to document this?

I thought of something like:

def foo(bar):
    """
    ...
    Parameters
    -----------
    bar: func(var1: list[str], var2: str) -> str
    """
    return bar(var1, var2)

Upvotes: 0

Views: 417

Answers (1)

Péter Leéh
Péter Leéh

Reputation: 2119

I'd do this way:

def foo(bar):
    """
    ...
    Parameters
    ----------
    bar: callable
        - ``var1``: description of parameter var1 (`list`).
        - ``var2``: description of parameter var2 (`str`).
    """
    return bar(var1, var2)

If you definitely need to include the return type of that internal function, then maybe:


def foo(bar):
    """
    ...
    Parameters
    ----------
    bar: callable

         ``bar(var1: list[str], var2: str) -> str``

    Some description about `var1` and `var2`.
    """
    return bar(var1, var2)

Upvotes: 1

Related Questions