hbutils.reflection.clazz¶
- Overview:
Useful functions for processing python classes and types.
class_wraps¶
-
hbutils.reflection.clazz.
class_wraps
(wrapped: type, assigned: Tuple[str] = '__module__', '__name__', '__qualname__', '__doc__', '__annotations__', updated: Tuple[str] = ())[source]¶ - Overview:
Wrapper decorator for class.
- Arguments:
wrapped (
type
): Wrapped class.- assigned (
Tuple[str]
): Wrapper assignments, equal tofunctools.wraps()
’s WRAPPER_ASSIGNMENTS
.
- assigned (
updated (
Tuple[str]
): Wrapper updates, default is()
, no update will be done.
- Examples:
>>> def cls_dec(clazz): >>> @class_wraps(clazz) >>> class _NewClazz(clazz): >>> pass >>> >>> return _NewClazz
common_base¶
-
hbutils.reflection.clazz.
common_base
(cls: type, *clss: type) → type[source]¶ - Overview:
Get common base class of the given classes. Only
__base__
is considered.- Arguments:
cls (
type
): First class.clss (
type
): Other classes.
- Returns:
base (
type
): Common base class.
- Examples::
>>> from hbutils.reflection import common_base >>> common_base(object) <class 'object'> >>> common_base(object, int, str) <class 'object'> >>> common_base(RuntimeError, ValueError, KeyError) <class 'Exception'>