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
clsobjects with custom methods and properties organized under a namespace. The namespace becomes accessible as an attribute onclsinstances, providing a clean way for users to add domain-specific functionality without modifying theclsclass 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 ofcls, e.g.adataforAnnData. 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)]]]