def __sub__(self, y): if not isinstance(y, Expression): raise OperatorError("supported operand only Expression instance" " for __sub__ Operator of Money") elif isinstance(y, BaseMoney) and y.currency == self.currency: return self.__class__(self.amount - y.amount, self.currency) else: return super(Money, self).__sub__(y)
def __init__(self, x, y): """ @param Expression x @param Expression y """ if not isinstance(x, Expression) or not isinstance(y, Expression): raise OperatorError("supported operand only instance of Expression" " for Minus Operator of Money") self.x, self.y = x, y
def __init__(self, augend, addend): """ @param Expression x @param Expression y """ if not isinstance(addend, Expression) or not isinstance( augend, Expression): raise OperatorError("supported operand only instance of Expression" " for Sum Operator of Money") self.x, self.y = augend, addend
def __init__(self, x, y): """ @param Expression x @param int,float y """ if type(y) not in (int, float, Decimal): raise OperatorError("supported operand only in types int,float" " for Div Operator of Money") y = Decimal(y) self.x, self.y = x, y
def __truediv__(self, y): if type(y) not in (int, float, Decimal): raise OperatorError("supported operand only in types int,float" " for Div Operator of Money") y = Decimal(str(y)) return self.__class__(self.left / y, self.right / y)
def __mul__(self, y): if type(y) not in (int, float, Decimal): raise OperatorError("supported operand only in types int,float" " for Mul Operator of Money") y = Decimal(str(y)) return DistributionAdd(self.left * y, self.right * y)
def __rtruediv__(self, x): raise OperatorError("supported operand only in types int,float" " for __rturediv__ Operator of Money")
def __truediv__(self, y): if type(y) not in (int, float, Decimal): raise OperatorError("supported operand only in types int,float" " for __turediv__ Operator of Money") y = Decimal(y) return self.__class__(self.amount / y, self.currency)