Documenting a duck-typed parameter in numpydoc

392 Views Asked by At

According to the convention in guide to numpy/scipy documentation function parameters should be documented in the following way:

def foo(x):
    """" This function does nothing

    Parameters
    ----------
    x : type
       Description of parameter `x`.
    """"
    pass

This is straightforward if type is a distinct type such as int or str.

Now I want the parameter to be an instance of BaseClass or any object that exposes the same interface (such as a class derived from BaseClass). Is there a convention how to concisely document that parameter x should expose a certain interface (by derivation or duck-typing)?

1

There are 1 best solutions below

0
On

The approach you described is pretty much the standard one.

Another approach is to use abstract base classes to define the specific methods that must be implemented and then specify that as the type as suggested on an answer to a related question.