segram.utils.docstrings module

Utility classes and methods for docstrings.

class segram.utils.docstrings.NumpyDocString(docstring_or_sections: str | dict[str, Any], /)[source]

Bases: object

Numpy 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 other docstring.

Parameters:
  • __default – Default merging behavior. If "append" then section content from other is appended to that of self. 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 NumpyDocString object.

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.