[Python-bugs-list] [ python-Bugs-408308 ] UserList.py bug in getslice, *add, mul

noreply@sourceforge.net noreply@sourceforge.net
Fri, 16 Mar 2001 10:00:17 -0800


Bugs item #408308, was updated on 2001-03-13 12:00
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=408308&group_id=5470

Category: Python Library
Group: None
>Status: Closed
Priority: 5
Submitted By: Daniel Haertle (dhaertle)
>Assigned to: Jeremy Hylton (jhylton)
Summary: UserList.py bug in getslice, *add, mul 

Initial Comment:
if one explitely initializes UserList in a class derived 
form Userlist, __getslice__, __*add__ and __mul__ do not 
work.

Consider the following code:

>>> import UserList
>>> class UL(UserList.UserList):
...    def __init__(self):
...       UserList.UserList.__init__(self)
... 
>>> ul=UL()
>>> ul.append(0); ul.append(1)
>>> ul[0:2]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "hd e18 yosi:programs:programing:python 
2.0c1:lib:UserList.py", line 27, in __getslice__
    return self.__class__(self.data[i:j])
TypeError: too many arguments; expected 1, got 2


A possible solution is to change UserList.py from

    def __getslice__(self, i, j):
        i = max(i, 0); j = max(j, 0)
        return self.__class__(self.data[i:j])

to

    def __getslice__(self, i, j):
        i = max(i, 0); j = max(j, 0)
        return self.data[i:j]

and the other methods accordingly. If for some reasons 
this is not possible, consider the code in Python1.5.2 
where __getslice__ works (but __*add__ and __mul__ 
don't)


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

>Comment By: Jeremy Hylton (jhylton)
Date: 2001-03-16 10:00

Message:
Logged In: YES 
user_id=31392

The subclass you've created -- UL -- is broken.  A subclass
of 
UserList should included an __init__ that supports an
initial list.  The definition of __getslice__ is correct,
because operations on
a UserList should return a UserList -- not a real list.


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

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