This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: slice obj with no start index is 0 instead of None sometimes
Type: Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: jyzude, rhettinger
Priority: normal Keywords:

Created on 2007-02-28 18:58 by jyzude, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
slicebug.py jyzude, 2007-02-28 19:04 Slice bug (with formatting preserved)
Messages (4)
msg31385 - (view) Author: Mike Verdone (jyzude) Date: 2007-02-28 18:58
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.
msg31386 - (view) Author: Mike Verdone (jyzude) Date: 2007-02-28 19:04
Correction! This is fixed in Python 3000. I just have too many windows open and too many branches checked out.
File Added: slicebug.py
msg31387 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-04-02 19:11
Fixing this small inconsistency has very little upside but runs the risk of breaking code that has been running fine for years.  I think we should punt.  If you agree, please close this bug report.
msg31388 - (view) Author: Mike Verdone (jyzude) Date: 2007-04-03 07:56
I concur. I'll close the bug.
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44636
2007-02-28 18:58:39jyzudecreate