segram.utils.docstrings module
Utility classes and methods for docstrings.
- class segram.utils.docstrings.NumpyDocString(docstring_or_sections: str | dict[str, Any], /)[source]
Bases:
objectNumpy docstring parser.
- sections
Sections dictionary.
- __init__(docstring_or_sections: str | dict[str, Any], /) None[source]
Initialization method.
- Parameters:
docstring_or_sections – Raw docstring text or sections dictionary.
- static parse_sections(text: str) dict[str, str][source]
Parse NumpyDoc style docstring sections.
- Parameters:
text – Docstring text.
- Returns:
Mapping from section names to their raw content.
- Return type:
dict
- merge(other: Self, *, _NumpyDocString__default: Literal['append', 'replace'] = 'append', **kwds: Any) Self[source]
Merge with
otherdocstring.- Parameters:
__default – Default merging behavior. If
"append"then section content fromotheris appended to that ofself. If"replace"then replaces it.**kwds – Keyword arguments can be used to set different merging policies (
"append"or"merge") other sections. The policy for the"header"section is by default set to"replace", so it has to be overriden here change this.
- Returns:
New
NumpyDocStringobject.- Return type:
doc
- segram.utils.docstrings.inherit_docstring(*args: Any, **kwds: Any) Callable[source]
Decorator for inheriting and mergin docstrings from parent classes.
- Parameters:
obj – Class or a method.
which – Whether to inherit from the direct parent class or from the first abstract base class in MRO.
spec – Dictionary mapping section names to either
"append"or"replace", which sets merge policies for different sections.default – Default mergin policy.