Why is __getslice__ still implemented?
exarkun at divmod.com
Tue Apr 10 16:57:04 CEST 2007
On Tue, 10 Apr 2007 08:35:56 -0600, Steven Bethard <steven.bethard at gmail.com> wrote:
>Torsten Bronger wrote:
>> According to <http://docs.python.org/ref/sequence-methods.html>,
>> __getslice__ is deprecated. At the moment, I derive an own class
>> from unicode and want to implement my own slicing. I found that I
>> have to override __getslice__ since __getitem__ isn't called when I
>> have something like my_instance[a:b] in my code.
>> According to
>> <news:mailman.7438.1102640455.5135.python-list at python.org>, this may
>> have efficiency reasons, however, I agree with
>> news:1102645919.114898.139820 at f14g2000cwb.googlegroups.com that this
>> is quite confusing. It forces people to implement a deprecated
>> function after all. I think the docs should say that you still have
>> to override __getslice__ when subclassing from a built-in type,
>> unless I really don't understand the issue correctly.
>Yes, you do still need to implement __getslice__ if you're subclassing
>a class (like unicode or list) which provides it. The __getslice__
>method can't be removed entirely for backwards compatibility reasons
>(though it is being removed in Python 3000). If you have a specific
>suggestion for what doc should be updated and how, that would be
>helpful. Please post it to:
Why does this mean that the unicode type has to implement __getslice__?
More information about the Python-list