Rationale behind the deprecation of __getslice__?
Carl Banks
imbosol at aerojockey.com
Thu Dec 9 17:30:06 EST 2004
Fernando Perez wrote:
> 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).
>
> The problem with this approach, besides a bit of code duplication, is
that
> classes which implement slicing must now do runtime type-checking
inside
> __getitem__.
I'm pretty sure it's to support multidimensional array slicing.
Consider an array reference such as a[1,2:5,4,6:9,10:]. Now what do
you do? You have mixed slices and indices. The
__getslice__/__getitem__ paradigm isn't versatile enough to handle this
situation. In that light, I'd say checking for slices is the lesser
evil.
As for why list objects still use getslice--they probably shouldn't.
I'd file a bug report.
--
CARL BANKS
More information about the Python-list
mailing list