Title: Merge xrange() into slice()
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum, rhettinger
Priority: normal Keywords: patch

Created on 2002-06-29 22:40 by rhettinger, last changed 2002-07-12 17:08 by gvanrossum. This issue is now closed.

File name Uploaded Description Edit
slice.diff rhettinger, 2002-06-29 22:40 Patch merging Xrange into Slice
slice2.diff rhettinger, 2002-06-30 19:35 Revised patch with Oren's suggestions
Messages (3)
msg40450 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-06-29 22:40
Xrange() and Slice() have evolved to be very similar.  
Merging the code for xrange() into slice() will 
complete the transformation, put all the capability 
into one object, eliminate an object type, eliminate 
two source files, and shrink the Python concept 
space by a modest amount.

Discussion on py-dev (see thread Xrange and Slices 
starting on 6/26/2002) was generally favorable. All 
of the design suggestions received have been 
incorporated in this patch.

Slice is left intact as a mutable container of arbitrary 
Python objects.  It's sq_item, sq_len, and tp_iter slots 
are filled in to give it the same sequence behavior as 
xrange().  The tp_iter slot creates an immutable 
iterator based on the state of the slice at the time the 
iterator is created.  The iterator uses c longs instead 
of PyObjects to protect its immutability and to keep 
the super fast speed that it had in xrange().

To keep the old xrange iterface intact, 'xrange' is 
made synonymous with 'slice'.  Also, slice.h is given 
macros and a PyRange_New() wrapper so that the 
xrange C API is left intact.

Two minor open issues:
1. Should repr() say 'slice' or 'xrange'?
2. What should the return value be for slice_length() 
when step is zero or None?

Patch passes all regression tests.  A news item 
should be added eventhough the APIs are unchanged.
msg40451 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-06-30 19:35
Logged In: YES 

New patch attached. Incorporates three ideas from Oren 
Tirosh's code review (int-->long, xrange as public interface, 
return -1 on len error).

I'm away from the computer for the next five weeks. Oren 
has agreed to champion my patches (not necessarily 
advocate, just make sure they get a fair trial and that 
requested changes get made).
msg40452 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-07-12 17:08
Logged In: YES 

Rejecting. It's better to let these two be different, so
that it's clear what the intended use is.
Date User Action Args
2002-06-29 22:40:51rhettingercreate