[ python-Bugs-1671137 ] slice obj with no start index is 0 instead of None sometimes

SourceForge.net noreply at sourceforge.net
Wed Feb 28 19:58:39 CET 2007


Bugs item #1671137, was opened at 2007-02-28 11:58
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1671137&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Mike Verdone (jyzude)
Assigned to: Nobody/Anonymous (nobody)
Summary: slice obj with no start index is 0 instead of None sometimes

Initial Comment:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1671137&group_id=5470


More information about the Python-bugs-list mailing list