summaryrefslogtreecommitdiff
path: root/scss/types.py
diff options
context:
space:
mode:
Diffstat (limited to 'scss/types.py')
-rw-r--r--scss/types.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/scss/types.py b/scss/types.py
index 3351f7f..d0079d3 100644
--- a/scss/types.py
+++ b/scss/types.py
@@ -462,7 +462,7 @@ class Number(Value):
return wrapped
- def to_python_index(self, length, check_bounds=True):
+ def to_python_index(self, length, check_bounds=True, circular=False):
"""Return a plain Python integer appropriate for indexing a sequence of
the given length. Raise if this is impossible for any reason
whatsoever.
@@ -477,13 +477,16 @@ class Number(Value):
if ret == 0:
raise ValueError("Index cannot be zero")
- if check_bounds and abs(ret) > length:
+ if check_bounds and not circular and abs(ret) > length:
raise ValueError("Index {0!r} out of bounds for length {1}".format(ret, length))
if ret > 0:
- return ret - 1
- else:
- return ret
+ ret -= 1
+
+ if circular:
+ ret = ret % length
+
+ return ret
@property
def has_simple_unit(self):