def match(self, other): typecheck(other, Units) if self is not other: raise Units.Mismatch( 'Units mismatch: {!r} vs {!r}', str(self), str(other), )
def __init__(self, spec, units=None): if units is None: (spec, units) = _parse_value(spec) typecheck(spec, Decimal) typecheck(units, Units) self.amount = spec self.units = units
def __div__(self, other): typecheck(other, Value) return Value(self.amount / other.amount, self.units / other.units)
def __mul__(self, other): typecheck(other, Value) return Value(self.amount * other.amount, self.units * other.units)
def __init__(self, decimal, units): typecheck(decimal, Decimal) typecheck(units, Units) self.amount = decimal self.units = units
def m(self, other): typecheck(other, Value) self.units.match(other.units) return method(self, other)
def test_ok(self): typecheck(3, int)
def match(self, other): typecheck(other, Units) if self is not other: raise UnitsMismatch(self, other)