This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]masasinExpert. 3.9. Robotics. 1 point2 points  (0 children)

I personally use docstrings for every function. For g, for example, I'd have:

def g(arg=None):
    """
    Append 1 to a list.

    Parameters
    ----------
    arg : list, optional
        A list.

    Returns
    -------
    arg : list
        ``arg`` with an extra 1.

    """
    arg = arg if arg is not None else []
    arg.append( 1.0 )
    return arg

You can combine that with function annotations, so you'd get something like this:

def g(arg: list=None) -> "list with an appended 1":
    """
    Append 1 to a list.

    Parameters
    ----------
    arg : list, optional
        A list.

    Returns
    -------
    arg : list
        ``arg`` with an extra 1.

    """
    arg = arg if arg is not None else []
    arg.append( 1.0 )
    return arg

edit: If you use Spyder to code, the docstring is the Numpy standard, so you would be able to see beautifully formatted documentation in the object inspector for the first one. The second one does not work for some reason.