Rationale behind the deprecation of __getslice__?

Fernando Perez fperez528 at yahoo.com
Thu Dec 9 16:23:21 EST 2004


Fernando Perez wrote:

> Hi all,
> 
> I was wondering if someone can help me understand why __getslice__ has been
> deprecated, yet it remains necessary to implement it for simple slices (i:j),
> while __getitem__ gets called for extended slices (i:j:k).

[...]

>     def __getitem__(self,key):
>         """called for single-element OR slice access"""
>         if type(key) is types.SliceType:
>             return Vector(list.__getitem__(self,key))
>         else:
>             return list.__getitem__(self,key)

I just realized that the type check is cleaner if done via

    def __getitem__(self,key):
        """called for single-element OR slice access"""
        if isinstance(key,slice):
            return Vector(list.__getitem__(self,key))
        else:
            return list.__getitem__(self,key)


Still, the core of my question remains.

TIA,

f




More information about the Python-list mailing list