scverse_misc.make_register_namespace_decorator

scverse_misc.make_register_namespace_decorator#

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

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.

If the scverse_misc Sphinx extension is enabled, the returned decorator will be documented 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 | None (default: None)) – Deprecated and unused.

  • docstring_style (str | None (default: None)) – Deprecated and unused.

Return type:

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