Author: Hakan Ardo <[email protected]>
Branch: step-one-xrange
Changeset: r55023:b06ec3240de4
Date: 2012-05-10 07:36 +0200
http://bitbucket.org/pypy/pypy/changeset/b06ec3240de4/
Log: only promote step if the argument was not given
diff --git a/pypy/module/__builtin__/functional.py
b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -312,22 +312,28 @@
class W_XRange(Wrappable):
- def __init__(self, space, start, len, step):
+ def __init__(self, space, start, len, step, promote_step=False):
self.space = space
self.start = start
self.len = len
self.step = step
+ self.promote_step = promote_step
- def descr_new(space, w_subtype, w_start, w_stop=None, w_step=1):
+ def descr_new(space, w_subtype, w_start, w_stop=None, w_step=None):
start = _toint(space, w_start)
- step = _toint(space, w_step)
+ if space.is_w(w_step, space.w_None): # no step argument provided
+ step = 1
+ promote_step = True
+ else:
+ step = _toint(space, w_step)
+ promote_step = False
if space.is_w(w_stop, space.w_None): # only 1 argument provided
start, stop = 0, start
else:
stop = _toint(space, w_stop)
howmany = get_len_of_range(space, start, stop, step)
obj = space.allocate_instance(W_XRange, w_subtype)
- W_XRange.__init__(obj, space, start, howmany, step)
+ W_XRange.__init__(obj, space, start, howmany, step, promote_step)
return space.wrap(obj)
def descr_repr(self):
@@ -356,7 +362,7 @@
space.wrap("xrange object index out of range"))
def descr_iter(self):
- if self.step == 1:
+ if self.promote_step and self.step == 1:
stop = self.start + self.len
return self.space.wrap(W_XRangeStepOneIterator(self.space,
self.start,
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit