1.1 --- a/lib/__builtins__/span.py Sat Dec 10 17:32:16 2016 +0100
1.2 +++ b/lib/__builtins__/span.py Sat Dec 10 17:35:58 2016 +0100
1.3 @@ -21,15 +21,15 @@
1.4
1.5 from __builtins__.sequence import _max, _min
1.6
1.7 -class xrange:
1.8 +class slice:
1.9
1.10 - "Implementation of xrange."
1.11 + "Implementation of slice."
1.12
1.13 NO_END = object()
1.14
1.15 - def __init__(self, start_or_end, end=NO_END, step=1):
1.16 + def __init__(self, start_or_end=None, end=NO_END, step=1):
1.17
1.18 - "Initialise the xrange with the given 'start_or_end', 'end' and 'step'."
1.19 + "Initialise the slice with the given 'start_or_end', 'end' and 'step'."
1.20
1.21 if end is xrange.NO_END:
1.22 self.start = 0
1.23 @@ -38,8 +38,30 @@
1.24 self.start = start_or_end
1.25 self.end = end
1.26
1.27 + if step == 0:
1.28 + raise ValueError(self.step)
1.29 +
1.30 self.step = step
1.31
1.32 + def __str__(self):
1.33 +
1.34 + "Return a string representation."
1.35 +
1.36 + b = buffer([self.__name__, "(", self.start, ", ", self.end, ", ", self.step, ")"])
1.37 + return str(b)
1.38 +
1.39 + __repr__ = __str__
1.40 +
1.41 +class xrange(slice):
1.42 +
1.43 + "Implementation of xrange."
1.44 +
1.45 + def __init__(self, start_or_end, end=slice.NO_END, step=1):
1.46 +
1.47 + "Initialise the xrange with the given 'start_or_end', 'end' and 'step'."
1.48 +
1.49 + get_using(slice.__init__, self)(start_or_end, end, step)
1.50 +
1.51 # Constrain the end according to the start and step.
1.52
1.53 if step > 0:
1.54 @@ -51,15 +73,6 @@
1.55
1.56 self.current = self.start
1.57
1.58 - def __str__(self):
1.59 -
1.60 - "Return a string representation."
1.61 -
1.62 - b = buffer([self.__name__, "(", self.start, ", ", self.end, ", ", self.step, ")"])
1.63 - return str(b)
1.64 -
1.65 - __repr__ = __str__
1.66 -
1.67 def __len__(self):
1.68
1.69 "Return the length of the range."
1.70 @@ -83,16 +96,6 @@
1.71 self.current += self.step
1.72 return current
1.73
1.74 -class slice(xrange):
1.75 -
1.76 - "Implementation of slice."
1.77 -
1.78 - def __init__(self, start_or_end=None, end=xrange.NO_END, step=1):
1.79 -
1.80 - "Initialise the slice with the given 'start_or_end', 'end' and 'step'."
1.81 -
1.82 - get_using(xrange.__init__, self)(start_or_end, end, step)
1.83 -
1.84 def range(start_or_end, end=None, step=1):
1.85
1.86 "Implementation of range."