summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWang Xuerui <idontknw.wang@gmail.com>2014-11-01 22:52:48 +0800
committerWang Xuerui <idontknw.wang@gmail.com>2014-11-01 22:52:48 +0800
commitd804c22987c20f1f607bda933a2b906f21dd315b (patch)
tree1bc6f1c8d7c56f2432adffced6f039fa4dbcd053
parent6809ba47746b312dcafaa95ae74692689d5c5d10 (diff)
downloadpyscss-d804c22987c20f1f607bda933a2b906f21dd315b.tar.gz
Implement modulo support in Number.
-rw-r--r--scss/types.py18
1 files changed, 18 insertions, 0 deletions
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):