From d804c22987c20f1f607bda933a2b906f21dd315b Mon Sep 17 00:00:00 2001 From: Wang Xuerui Date: Sat, 1 Nov 2014 22:52:48 +0800 Subject: Implement modulo support in Number. --- scss/types.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scss/types.py b/scss/types.py index 092f93b..54345da 100644 --- a/scss/types.py +++ b/scss/types.py @@ -396,6 +396,24 @@ class Number(Value): return Number(amount, unit_numer=numer, unit_denom=denom) + def __mod__(self, other): + if not isinstance(other, Number): + return NotImplemented + + amount = self.value % other.value + + if self.is_unitless: + return Number(amount) + + if not other.is_unitless: + left = self.to_base_units() + right = other.to_base_units() + + if left.unit_numer != right.unit_numer or left.unit_denom != right.unit_denom: + raise ValueError("Can't reconcile units: %r and %r" % (self, other)) + + return Number(amount, unit_numer=self.unit_numer, unit_denom=self.unit_denom) + def __add__(self, other): # Numbers auto-cast to strings when added to other strings if isinstance(other, String): -- cgit v1.2.1