Rationale behind the deprecation of __getslice__?

Steven Bethard steven.bethard at gmail.com
Fri Dec 10 00:37:57 CET 2004

Carl Banks wrote:
> As for why list objects still use getslice--they probably shouldn't.
> I'd file a bug report.

I'm not convinced this is actually a bug; it works just like the docs 

__getslice__(  	self, i, j)
Called to implement evaluation of self[i:j].
If no __getslice__() is found, a slice object is created instead, and 
passed to __getitem__() instead.
For slice operations involving extended slice notation, or in absence of 
the slice methods, __getitem__(), __setitem__() or __delitem__() is 
called with a slice object as argument.

So the docs imply that if __getslice__ exists, it will be used before 
trying __getitem__.  Since list defines __getslice__, list.__getslice__ 
will be used before __getitem__ in any class that inherits from list.

This is certainly a wart though.  I'd love to see list.__getslice__ 
removed, leaving only list.__getitem__, but I suspect that this kind of 
backwards-incompatible change would be frowned on...

Guess we could file a feature request?


More information about the Python-list mailing list