<commit_before>from functools import wraps
import operator


def math_method(name, right=False):
    math_func = getattr(operator, name)

    @wraps(math_func)
    def wrapper(self, other):
        value = self.value

        if right:
            value, other = other, value

        result = math_func(value, other)
        return type(self)(result, units=self.units)

    return wrapper


class MimicFloat(type):

    math_methods = ('__add__', '__sub__', '__mul__', '__truediv__')
    math_rmethods = ('__radd__', '__rsub__', '__rmul__', '__rtruediv__')

    def __new__(cls, name, bases, namespace):
        for method in cls.math_methods:
            namespace[method] = math_method(method)

        for rmethod in cls.math_rmethods:
            method = rmethod.replace('__r', '__')
            namespace[rmethod] = math_method(method, right=True)

        return super(MimicFloat, cls).__new__(cls, name, bases, namespace)<commit_msg>Added support for unary operators in MimicFloat<commit_after>from functools import wraps
import operator


def math_method(name, right_operator=False):
    math_func = getattr(operator, name)

    @wraps(math_func)
    def wrapper(*args):
        args = list(args)  # [self, other] - binary operators, [self] - unary
        self = args[0]
        args[0] = self.value

        if right_operator:
            args = args[::-1]  # args: self, other -> other, self

        result = math_func(*args)
        return type(self)(result, units=self.units)

    return wrapper


class MimicFloat(type):

    math_methods = (
        '__add__', '__sub__', '__mul__', '__truediv__',
        '__pos__', '__neg__',
    )
    math_rmethods = ('__radd__', '__rsub__', '__rmul__', '__rtruediv__')

    def __new__(cls, name, bases, namespace):
        for method in cls.math_methods:
            namespace[method] = math_method(method)

        for rmethod in cls.math_rmethods:
            method = rmethod.replace('__r', '__')
            namespace[rmethod] = math_method(method, right_operator=True)

        return super(MimicFloat, cls).__new__(cls, name, bases, namespace)
{'fraction_non_alphanumeric': 0.11728395061728394, 'fraction_numerical': 0.0014245014245014246, 'mean_word_length': 2.9829867674858224, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5074569', 'n_tokens_mistral': 689, 'n_tokens_neox': 675, 'n_words': 158}