[Python-bugs-list] [ python-Bugs-491398 ] Sliced list subclass has wrong type
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 10 Dec 2001 18:17:10 -0800
Bugs item #491398, was opened at 2001-12-10 18:17
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=491398&group_id=5470
Category: Python Interpreter Core
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Nobody/Anonymous (nobody)
Summary: Sliced list subclass has wrong type
Initial Comment:
In Python2.2b2, there is a change in behavior between
a sub-class of list and a sub-class of UserList.
The library code for UserList.Py in Python 2.1.1 shows
an intent to maintain the class as an invariant by
coercing the object being sliced.
def __getslice__(self, i, j):
i = max(i, 0); j = max(j, 0)
return self.__class__(self.data[i:j])
In the Python2.2b2, this behavior changes and the
slice is returned as a list rather than the class of
the object being sliced.
Example code showing the difference:
import UserList
class L(UserList.UserList):
pass
p = L(['a','b','c','d'])
print p.__class__ # Original object is of class L
print p[1:].__class__ # Sliced object is also class L
class M(list):
pass
q = M(['a','b','c','d'])
print q.__class__ # Original object is of class M
print q[1:].__class__ # Sliced object in NOT of
# class M, but becomes a list!
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=491398&group_id=5470