scverse_misc.make_register_namespace_decorator

scverse_misc.make_register_namespace_decorator#

scverse_misc.make_register_namespace_decorator(cls, canonical_instance_name, decorator_name, docstring_style)#

Create a decorator for registering custom functionality with a class.

The decorator will allow your users to extend cls objects with custom methods and properties organized under a namespace. The namespace becomes accessible as an attribute on cls instances, providing a clean way for users to add domain-specific functionality without modifying the cls class itself.

The return decorator will have a docstring describing how to use it along with examples.

Parameters:
  • cls (type) – The class to be made extensible.

  • canonical_instance_name (str) – The typical name of an instance of cls, e.g. adata for AnnData. This is used for run-time checking of constructor signatures of the namespace classes.

  • decorator_name (str) – The name under which the decorator is accessible in your package. This is used for the examples in the decorator docstring.

  • docstring_style (Literal['google', 'numpy', 'scverse']) – Whether the docstring of the generated decorator should conform to "numpy" or "google" style. We also support variant of "numpy" called "scverse", which does not duplicate type annotation in docstrings.

Return type:

Callable[[str], Callable[[type[TypeVar(NameSpT, bound= ExtensionNamespace)]], type[TypeVar(NameSpT, bound= ExtensionNamespace)]]]