Skip to content

mixins

mixins

Defines inputs

ArrayDunders

Bases: NumericDunders

A mixin class that extends NumericDunders with additional array-like behavior.

NumericDunders

A mixin class containing numeric dunder methods that can be applied to any class via composition

Attributes:

Name Type Description
RESERVED_NAME str

Name of the reserved attribute that holds the value

get_value classmethod

get_value(instance)

Get the value of the instance

Parameters:

Name Type Description Default
instance Any

Instance of the class

required

Returns:

Name Type Description
Any

Value of the instance stored in the reserved attribute or else returns the instance. For example, if the reserved attribute is 'value', then it returns instance.value else if the instance is just a float or an int or something like that, then it returns the instance itself.

Source code in src/data_handlers/mixins.py
@classmethod
def get_value(cls, instance):
    """
    Get the value of the instance

    Args:
        instance (Any): Instance of the class

    Returns:
        Any: Value of the instance stored in the reserved attribute or else returns the instance.
            For example, if the reserved attribute is 'value', then it returns `instance.value` else
            if the instance is just a float or an int or something like that, then it returns the instance itself.
    """
    return getattr(instance, cls.RESERVED_NAME, instance)