Issue 1671137: slice obj with no start index is 0 instead of None sometimes (original) (raw)

Slice objects returned by the slice ":42" return different slice objects depending on whether the entire slice operation is simple or extended. This bit of code explains it best:

class SliceBug: def getitem(self, sliceArg): print sliceArg

s = SliceBug()

s[:42] s[:42,]

s[:42] produces slice(0, 42, None) s[:42,] produces (slice(None, 42, None),)

Note that this bug only occurs on classes that do no inherit from object ("old style" classes). If you change the class to make it inherit from "object" both slices have None as their start index. Oddly enough in Python 3000 it still only happens on "old style" classes even though supposedly they are the same as new style classes. I have also reproduced the bug in Python 2.6, 2.4, 2.3, and 2.2. Seems to be a long standing bug/feature.