Rationale behind the deprecation of __getslice__?

Fernando Perez fperez528 at yahoo.com
Thu Dec 9 17:18:11 EST 2004


Steven Bethard wrote:

> Fernando Perez wrote:
>> classes which implement slicing must now do runtime type-checking inside
>> __getitem__.
> 
> Just in case you thought that they wouldn't have to do runtime
> type-checking otherwise:
> 
>  >>> class C(object):
> ...     def __getitem__(self, x):
> ...         print type(x), x
> ...

[...]

> You can put just about anything in a __getitem__ call.  Do you really
> want a method for each of the variants above?

I guess that conceptually it just felt natural to me to keep separate methods
for dealing with a slice (get many elements out) and other types of indexing,
which I tend to think of as 'scalar' indexing.

Regards,

f




More information about the Python-list mailing list