scverse_doc.napoleon#
Prose return sections in NumPy-style docstrings.
sphinx.ext.napoleon reads a NumPy-style Returns section as a list of name : type entries.
With this extension, it can be prose instead:
Returns
-------
The fitted model, or `None` if `copy` is false.
Lines that do look like name : type become an item linking to type.
If the section is a single definition list with n items,
and the return type is a tuple with n members (or a union with such a tuple),
each item is annotated with its member type,
e.g. for a function annotated -> tuple[AnnData, AnnData]:
Returns
-------
train
The training set.
test
The test set.
Examples#
def split(items: list[str], frac: float = 0.8) -> tuple[list[str], list[str]]:
"""Split `items` into a training and a test set.
Returns
-------
train
The first `frac` of `items`.
test
The rest.
"""
n = round(len(items) * frac)
return items[:n], items[n:]
- examples.split(items: list[str], frac: float = 0.8) tuple[list[str], list[str]][source]#
Split
itemsinto a training and a test set.
def find(items: list[str], item: str) -> int | None:
"""Find `item` in `items`.
Returns
-------
The index of `item`, or `None` if it isn’t in `items`.
"""
return items.index(item) if item in items else None