Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

#
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 'true_divide'>
        ),
        __radd__=dict(
            func=<function <lambda> at 0x7ff3592d5480>
        ),
        __rsub__=dict(
            func=<function <lambda> at 0x7ff3592d5510>
        ),
        __rmul__=dict(
            func=<function <lambda> at 0x7ff3592d55a0>
        ),
        __rpow__=dict(
            func=<function <lambda> at 0x7ff3592d5630>
        ),
        __rmod__=dict(
            func=<function <lambda> at 0x7ff3592d56c0>
        ),
        __rfloordiv__=dict(
            func=<function <lambda> at 0x7ff3592d5750>
        ),
        __rtruediv__=dict(
            func=<function <lambda> at 0x7ff3592d57e0>
        ),
        __and__=dict(
            func=<ufunc 'bitwise_and'>
        ),
        __or__=dict(
            func=<ufunc 'bitwise_or'>
        ),
        __xor__=dict(
            func=<ufunc 'bitwise_xor'>
        ),
        __rand__=dict(
            func=<function <lambda> at 0x7ff3592d5870>
        ),
        __ror__=dict(
            func=<function <lambda> at 0x7ff3592d5900>
        ),
        __rxor__=dict(
            func=<function <lambda> at 0x7ff3592d5990>
        )
    )

## 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.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings