Why is __getslice__ still implemented?
jstroud at mbi.ucla.edu
Tue Apr 10 12:24:02 CEST 2007
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.
Which version of python are you using?
chernev 20% /sw/bin/python
Python 2.5 (r25:51908, Oct 10 2006, 03:45:47)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
py> class Bob(object):
... def __getitem__(self, *args):
... print args
py> b = Bob()
(slice(4, 21, 2),)
((slice(5, 18, 21), slice(2, 9, 2), 8, slice(14, 4, None)),)
More information about the Python-list