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: UserList.py bug in getslice, *add, mul
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: jhylton Nosy List: dhaertle, jhylton
Priority: normal Keywords:

Created on 2001-03-13 20:00 by dhaertle, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (2)
msg3864 - (view) Author: Daniel Haertle (dhaertle) Date: 2001-03-13 20:00
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)
msg3865 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2001-03-16 18:00
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.
History
Date User Action Args
2022-04-10 16:03:51adminsetgithub: 34145
2001-03-13 20:00:13dhaertlecreate