slices such as a[:7] give a key of slice(0,7,None) whereas a[:7.1] gives a key of slice(None,7.1,None) Slices should not assume that the object indices begin at zero, since that is actually a characteristic of the object. The current behavior cripples an object that wants, say, to start its indices with negative numbers. a[:7] should pass a key of slice(None,7,None). Thanks! russt@agilityfund.com
Logged In: YES user_id=760126 'slice' doesn't round its arguments. The difference is whether you pass an integer or a float as part of the slice. Thus: a[:7] gives a key of slice(0,7,None) while a[:7.0] gives a key of slice(None,7.0,None) What's going on I suspect is that the python has two different behaviours for __getitem__. The first handles slices with integer only components, and defaults to starting at zero. The second handles anything else. This is probably done in order to accomodate old 'list' and 'tuple' implementation code that doesn't accept starting indices of None. But the best solution would be to eliminate the dual behavior of slice and revise the list and tuple code to accept the more general behavior.
Logged In: YES user_id=80475 Russ, you're right about there being two behaviors for the implementation of the slice notation(see apply_slice() in Python/ceval.c). This occurs in the bytecode interpreter rather than some object's implementation of __getitem__. While it is unfortunate, it can't be fixed without breaking code which defines __getitem__ but doesn't provide a None- to-zero converter. Factiod of the day, interpreter doesn't just assume 0 for None, it clamps the values in a range of 0<= value <= sys.maxint: >>> class C: def __getitem__(self, i): return i >>> c = C() >>> c[10000000000000000000L:] slice(2147483647, 2147483647, None) I recommend you close the bug as Won't Fix.