Skip to content

magic_decorators module

Class decorators for attaching magic methods.


binary_magic_config ReadonlyConfig

Config of binary magic methods to be attached to a class.

ReadonlyConfig(
    __eq__=dict(
        func=<ufunc 'equal'>
    ),
    __ne__=dict(
        func=<ufunc 'not_equal'>
    ),
    __lt__=dict(
        func=<ufunc 'less'>
    ),
    __gt__=dict(
        func=<ufunc 'greater'>
    ),
    __le__=dict(
        func=<ufunc 'less_equal'>
    ),
    __ge__=dict(
        func=<ufunc 'greater_equal'>
    ),
    __add__=dict(
        func=<ufunc 'add'>
    ),
    __sub__=dict(
        func=<ufunc 'subtract'>
    ),
    __mul__=dict(
        func=<ufunc 'multiply'>
    ),
    __pow__=dict(
        func=<ufunc 'power'>
    ),
    __mod__=dict(
        func=<ufunc 'remainder'>
    ),
    __floordiv__=dict(
        func=<ufunc 'floor_divide'>
    ),
    __truediv__=dict(
        func=<ufunc 'divide'>
    ),
    __radd__=dict(
        func=<function <lambda> at 0x132099940>
    ),
    __rsub__=dict(
        func=<function <lambda> at 0x13209a3e0>
    ),
    __rmul__=dict(
        func=<function <lambda> at 0x13209a480>
    ),
    __rpow__=dict(
        func=<function <lambda> at 0x13209a520>
    ),
    __rmod__=dict(
        func=<function <lambda> at 0x13209a5c0>
    ),
    __rfloordiv__=dict(
        func=<function <lambda> at 0x13209a660>
    ),
    __rtruediv__=dict(
        func=<function <lambda> at 0x13209a700>
    ),
    __and__=dict(
        func=<ufunc 'bitwise_and'>
    ),
    __or__=dict(
        func=<ufunc 'bitwise_or'>
    ),
    __xor__=dict(
        func=<ufunc 'bitwise_xor'>
    ),
    __rand__=dict(
        func=<function <lambda> at 0x13209a7a0>
    ),
    __ror__=dict(
        func=<function <lambda> at 0x13209a840>
    ),
    __rxor__=dict(
        func=<function <lambda> at 0x13209a8e0>
    )
)

unary_magic_config ReadonlyConfig

Config of unary magic methods to be attached to a class.

ReadonlyConfig(
    __neg__=dict(
        func=<ufunc 'negative'>
    ),
    __pos__=dict(
        func=<ufunc 'positive'>
    ),
    __abs__=dict(
        func=<ufunc 'absolute'>
    ),
    __invert__=dict(
        func=<ufunc 'invert'>
    )
)

attach_binary_magic_methods function

attach_binary_magic_methods(
    translate_func,
    config=None
)

Class decorator to attach binary magic methods to a class.

translate_func must

  • take self, other, and unary function,
  • perform computation, and
  • return the result.

config defaults to binary_magic_config and must contain target method names (keys) and dictionaries (values) with the following keys:

  • func: Function that combines two array-like objects.

attach_unary_magic_methods function

attach_unary_magic_methods(
    translate_func,
    config=None
)

Class decorator to attach unary magic methods to a class.

translate_func must

  • take self and unary function,
  • perform computation, and
  • return the result.

config defaults to unary_magic_config and must contain target method names (keys) and dictionaries (values) with the following keys:

  • func: Function that transforms one array-like object.