[lxml-dev] operator.delslice() not working with 2.1beta3

Stefan Behnel stefan_ml at behnel.de
Fri Jun 20 21:37:26 CEST 2008


Hi,

Holger Joukl wrote:
> I just realized that operator.delslice() does not work with 2.1beta3:
> 
>  >>> root = msg
>>>> root.a = [1,2,3,4]
>>>> import operator
>>>> operator.delslice(msg.a, 0, 4)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: object doesn't support slice deletion
>  which worked in  2.0alpha
> 
>  >>> root = msg
>>>> root.a = [1,2,3,4]
>>>> import operator
>>>> operator.delslice(msg.a, 0, 4)
>>>>
>  I suspect this was introduced with extended slicing.
> 
>  operator.getslice and operator.setslice still work, btw.

Hmmm, yes, the operator maps to a pretty direct call of PySequence_DelSlice(),
which internally does this:

        m = s->ob_type->tp_as_sequence;
        if (m && m->sq_ass_slice) {
             ...
        }
        type_error("'%.200s' object doesn't support slice deletion", s);
        return -1;

So to make this work, I'll have to wrap __delitem__() in a deprecated
__delslice__(). That's ugly...

Stefan



More information about the lxml-dev mailing list