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 promise:


------------------------------------------------------------
http://docs.python.org/ref/sequence-methods.html
__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?

Steve
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to