from __future__ import absolute_import

def add_operators(operator_decorator, hash_function = None):
    def add_operators_decorator(target_class):
        @operator_decorator
        def __add__(self, other):
            return self + other
        target_class.__add__ = __add__

        @operator_decorator
        def __radd__(self, other):
            return self + other
        target_class.__radd__ = __radd__

        @operator_decorator
        def __sub__(self, other):
            return self - other
        target_class.__sub__ = __sub__

        @operator_decorator
        def __rsub__(self, other):
            return other - self
        target_class.__rsub__ = __rsub__

        @operator_decorator
        def __mul__(self, other):
            return self * other
        target_class.__mul__ = __mul__

        @operator_decorator
        def __rmul__(self, other):
            return self * other
        target_class.__rmul__ = __rmul__

        @operator_decorator
        def __div__(self, other):
            return self / other
        target_class.__div__ = __div__

        @operator_decorator
        def __rdiv__(self, other):
            return other / self
        target_class.__rdiv__ = __rdiv__

        @operator_decorator
        def __truediv__(self, other):
            return self / other
        target_class.__truediv__ = __truediv__

        @operator_decorator
        def __rtruediv__(self, other):
            return other / self
        target_class.__rtruediv__ = __rtruediv__

        target_class.__hash__ = hash_function

        return target_class

    return add_operators_decorator