treevalue.utils.clazz

class_wraps

treevalue.utils.clazz.class_wraps(original_class: Type[_ClassType])[source]
Overview:

Wrap class like functools.wraps, can be used in class decorators.

Arguments:
  • original_class (Type[_ClassType]): Original class for wrapping.

Example:
>>> def cls_dec(clazz):
>>>     @class_wraps(clazz)
>>>     class _NewClazz(clazz):
>>>         pass
>>>
>>>     return _NewClazz

init_magic

treevalue.utils.clazz.init_magic(init_decorator)[source]
Overview:

Magic for initialization function of a class.

Arguments:
  • init_decorator (Callable): Initialization function decorator.

Example:
>>> from functools import wraps
>>>
>>> def _init_dec(func):
>>>     @wraps(func)
>>>     def _new_func(value):
>>>         func(value + 1)
>>>
>>>     return _new_func
>>>
>>> @init_magic(_init_dec)
>>> class Container:
>>>     def __init__(self, value):
>>>         self.__value = value
>>>
>>>     @property
>>>     def value(self):
>>>         return self.__value
>>>
>>> c = Container(1)
>>> c.value   # 2
>>> c2 = Container(33)
>>> c2.value  # 34

common_bases

treevalue.utils.clazz.common_bases(*classes: Type, base: Optional[Union[Collection[Type], Type]] = None) → Set[Type][source]
Overview:

Get all the common bases of the classes.

Arguments:
  • classes (Type): Target classes.

  • base (Union[Collection[Type], Type, None]): Limit of the base class, default is None which means no limit.

Returns:
  • bases (Set[Type]): A set of classes which is the common bases of the classes, only high leveled classes will be kept.

common_direct_base

treevalue.utils.clazz.common_direct_base(*classes: Type, base: Optional[Union[Collection[Type], Type]] = None)[source]
Overview:

Get the common direct base of the classes.

Arguments:
  • classes (Type): Target classes.

  • base (Union[Collection[Type], Type, None]): Limit of the base class, default is None which means no limit.

Returns:
  • base (Type): A class which is all the bases.

get_class_full_name

treevalue.utils.clazz.get_class_full_name(clazz: type)[source]
Overview:

Get full name of a class.

Arguments:
  • clazz (type): Given class.

Returns:
  • name (str): Full name of the given class.