#!/usr/bin/python class LengthAccumulator(object): def __init__(self): self.number = 1 def __neg__(self): self.number += 1 class LengthLiteral(object): def __neg__(self): return LengthAccumulator() def __sub__(self, other): if isinstance(other, LengthAccumulator): return other.number + 1 else: return 1 I = LengthLiteral() if __name__ == "__main__": assert I-I == 1 assert I--I == 2 assert I------I == 6