Инкремент

admin, 13 февраля 2022 г. 23:38


class Inc():
    def __init__(self, value=0):
        self.initial = value
        self.value = value

    def __index__(self):
        return self.value

    def __pos__(self):
        self.value += 1
        return self.value

    def __neg__(self):
        self.value -= 1
        return self.value

    def __invert__(self):
        self.value = self.initial
        return self.value

NUMBATWO

class inc(int):

    def __index__(self):
        return self

    def __pos__(self):
        return inc(self+1)

    def __neg__(self):
        return inc(self-1)

    def __add__(self, other):
        return inc(super().__add__(other))

    def __sub__(self, other):
        return inc(super().__sub__(other))

    def __mul__(self, other):
        return inc(super().__mul__(other))

    def __floordiv__(self, other):
        return inc(super().__floordiv__(other))

    def __mod__(self, other):
        return inc(super().__mod__(other))

    def __pow__(self, other):
        return inc(super().__pow__(other))

    def __iadd__(self, other):
        return inc(super().__iadd__(other))

    def __isub__(self, other):
        return inc(super().__isub__(other))

    def __imul__(self, other):
        return inc(super().__imul__(other))

    def __ifloordiv__(self, other):
        return inc(super().__ifloordiv__(other))

    def __imod__(self, other):
        return inc(super().__imod__(other))

    def __ipow__(self, other):
        return inc(super().__ipow__(other))