[Python-bugs-list] [ python-Bugs-633152 ] list slice ass ignores subtypes of list

noreply@sourceforge.net noreply@sourceforge.net
Tue, 05 Nov 2002 10:15:46 -0800


Bugs item #633152, was opened at 2002-11-04 08:19
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=633152&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Ronald Oussoren (ronaldoussoren)
Assigned to: Nobody/Anonymous (nobody)
Summary: list slice ass ignores subtypes of list

Initial Comment:
When assigning a subtype of list to a list slice the implementation 
of slice-assignment directly accesses the list representation and 
ignores any modified accessor functions:

class MyList  (list):
    def __getitem__(self, idx):
        if idx % 2 == 0:
            return 'E'
        return 'O'

mylst = MyList()
mylst.append(1)
mylst.append(1)

lst = [ 1, 2, 3, 4]
lst [2:3] = mylst
print lst
# prints [1, 2, 1, 1, 4] I'd expect it to print [1, 2, 'E', 'O', 4 ]

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

>Comment By: Michael Hudson (mwh)
Date: 2002-11-05 18:15

Message:
Logged In: YES 
user_id=6656

I think this is now fixed, via a somewhat different approach.

You might want to check, though.

While we're at it, there are a bunch of problems with your
patch (for future reference):

1) it contains a bunch of NUL bytes!
2) it's a straight diff.  we like context (-c) or unified
(-u) diffs.  most people prefer context diffs, I think. 
Bass players (e.g. Barry) prefer unified.
3) it has no error checking at all!

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

Comment By: Ronald Oussoren (ronaldoussoren)
Date: 2002-11-04 11:04

Message:
Logged In: YES 
user_id=580910

The attached patch (list_ass_slice.patch) updates the implementation of 
slice assigment for lists: If the RHS is a list (exact match) use the 
current implementation and if the RHS is a sequence use 
PySequence_GetItem.

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

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