Skip to content

Support customized type documentation #5

@augustebaum

Description

@augustebaum

Sometimes it can make sense to have a custom, more readable description of the argument where the raw type would be:

A = int | str
Listable[T] = T | list[T]

def f(a: Listable[A]):
    """Do something.
    
    Parameters
    ----------
    a : int or str or list of such objects
        The input.
    """

In this case (and I would hope, many others), it would be cool to automate the human-readable type documentation, e.g.

# Introducing `TypeDescription`, to differentiate it from
# `Description` which is really more of a "parameter description"
MyUnion = Annotated[Union, TypeDescription(lambda types: " or ".join(map(str, types)))]

Input = Annotated[MyUnion[int, str, bool], Description("The input.")]

@docstring("numpydoc")
def f(a: Input):
    """Do something."""

which would result in

Help on ParsedFunc in module docstrands.parsed_func:

<function f>
    Do something.

    Parameters
    ----------
    a : int or str or bool
        The input.

When I discovered DocStrands this is one of the features I looked for.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions