<div class="gmail_quote">On Wed, Oct 31, 2012 at 7:42 AM, Andrew Robinson <span dir="ltr"><<a href="mailto:andrew3@r3dsolutions.com" target="_blank">andrew3@r3dsolutions.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Then; I'd note:  The non-goofy purpose of slice is to hold three data values;  They are either numbers or None.  These *normally* encountered values can't create a memory loop.<br>
So, FOR AS LONG, as the object representing slice does not contain an explicit GC pair; I move that we mandate (yes, in the current python implementation, even as a *fix*) that its named members may not be assigned any objects other than None or numbers....<br>


<br>
eg: Lists would be forbidden....<br>
<br>
Since functions, and subclasses, can be test evaluated by int( the_thing_to_try ) and *[] can too,<br>
generality need not be lost for generating nothing or numbers.<br></blockquote><div><br>PEP 357 requires that anything implementing the __index__ special method be allowed for slicing sequences (and also that __index__ be used for the conversion).  For the most part, that includes ints and numpy integer types, but other code could be doing esoteric things with it.<br>

<br>The change would be backward-incompatible in any case, since there is certainly code out there that uses non-numeric slices -- one example has already been given in this thread.<br>And more wonderful yet, when I do extended slice replacement -- it gives me results beyond my wildest imaginings!<br>

</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">>>> a=[0,1,2,3,4,5]<br>
>>> a[4:5]=range( 0, 3 ) # Size origin=1, Size dest =3<br>
>>> a<br>
[0, 1, 2, 3, 0, 1, 2, 5]  # Insert on top of replacement<br>
>>><br>
But !!!NOT!!! if I do it this way:<br>
>>> a[4]=range( 0, 3 )<br>
>>> a<br>
[0, 1, 2, 3, range(0, 3), 1, 2, 5]<br>
>>><br></blockquote></div><br>That's nothing to do with range or Python 3.  It's part of the difference between slice assignment and index assignment.  The former unpacks an iterable, and the latter assigns a single object.  You'd get the same behavior with lists:<br>

<br>>>> a = list(range(6))<br>>>> a[4:5] = list(range(3))<br>>>> a<br>[0, 1, 2, 3, 0, 1, 2, 5]<br>>>> a = list(range(6))<br>>>> a[4] = list(range(3))<br>>>> a<br>[0, 1, 2, 3, [0, 1, 2], 5]<br>

<br>Slice assignment unpacks the list; index assignment assigns the list itself at the index.<br>