polymerist.genutils.decorators.classmod
Decorators for modifying classes
Attributes
Functions
|
Class decorator for auto-generating __repr__ methods |
|
Parametric class decorator for automatically generating a registry of subclasses of a target class |
|
Register a list of string attribute names as abstract class attributes, |
Module Contents
- polymerist.genutils.decorators.classmod.C
- polymerist.genutils.decorators.classmod.generate_repr(cls: C | None = None, disp_attrs: Iterable[str] | None = None, lookup_attr: str | None = None) C | Callable[[C], C][source]
Class decorator for auto-generating __repr__ methods
By default (i.e. with no arguments), generated repr simply returns the name of the class If collection of “disp_attrs” is provided, will display the values of <disp_attrs> for the object instance being represented in series If “disp_attrs” is NOT provided but “lookup_attr” is, disp_attrs will be looked up from the modified parent class
- polymerist.genutils.decorators.classmod.register_subclasses(cls: C | None = None, key_attr: str = '__name__', reg_attr: str = 'subclass_registry') C | Callable[[C], C][source]
Parametric class decorator for automatically generating a registry of subclasses of a target class Binds registry to the “registry” class property in the target class
Subclasses are keyed by lookup of a target attribute <key_attr> in the child classes (by default just the name of the subclass), while the resulting registry class property is bound to the <reg_attr> attribute of the parent class