Esempio n. 1
0
 def match(self, other):
     typecheck(other, Units)
     if self is not other:
         raise Units.Mismatch(
             'Units mismatch: {!r} vs {!r}',
             str(self),
             str(other),
         )
Esempio n. 2
0
    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
Esempio n. 3
0
 def __div__(self, other):
     typecheck(other, Value)
     return Value(self.amount / other.amount, self.units / other.units)
Esempio n. 4
0
 def __mul__(self, other):
     typecheck(other, Value)
     return Value(self.amount * other.amount, self.units * other.units)
Esempio n. 5
0
    def __init__(self, decimal, units):
        typecheck(decimal, Decimal)
        typecheck(units, Units)

        self.amount = decimal
        self.units = units
Esempio n. 6
0
 def m(self, other):
     typecheck(other, Value)
     self.units.match(other.units)
     return method(self, other)
Esempio n. 7
0
 def test_ok(self):
     typecheck(3, int)
Esempio n. 8
0
 def match(self, other):
     typecheck(other, Units)
     if self is not other:
         raise UnitsMismatch(self, other)