Why is __getslice__ still implemented?

T

Torsten Bronger

Hallöchen!

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
<this may
have efficiency reasons, however, I agree with
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.

Tschö,
Torsten.
 
J

James Stroud

Torsten said:
Hallöchen!

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
<this may
have efficiency reasons, however, I agree with
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.

Tschö,
Torsten.

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()
py> b[4:21:2]
(slice(4, 21, 2),)
py> b[5:18:21,2:9:2,8,14:4]
((slice(5, 18, 21), slice(2, 9, 2), 8, slice(14, 4, None)),)
 
T

Torsten Bronger

Hallöchen!

James said:
[...]

Which version of python are you using?
2.4

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

This should be Bob(unicode).
... def __getitem__(self, *args):
... print args
...
py> b = Bob()
py> b[4:21:2]
(slice(4, 21, 2),)
py> b[5:18:21,2:9:2,8,14:4]
((slice(5, 18, 21), slice(2, 9, 2), 8, slice(14, 4, None)),)

Tschö,
Torsten.
 
S

Steven Bethard

Torsten said:
Hallöchen!

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
<this may
have efficiency reasons, however, I agree with
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:

http://sourceforge.net/tracker/?group_id=5470&atid=105470

(It doesn't need to be a real patch. Plain text is fine as long as you
indicate where in the documentation it needs to go.)

Steve
 
T

Torsten Bronger

Hallöchen!

Steven said:
Torsten said:
[...]

[...] 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.

[...] If you have a specific suggestion for what doc should be
updated and how, that would be helpful. Please post it to:

http://sourceforge.net/tracker/?group_id=5470&atid=105470

Done.

Tschö,
Torsten.
 
S

Steven Bethard

Torsten said:
Hallöchen!

Steven said:
Torsten said:
[...]

[...] 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.
[...] If you have a specific suggestion for what doc should be
updated and how, that would be helpful. Please post it to:

http://sourceforge.net/tracker/?group_id=5470&atid=105470

Done.

Thanks!

STeVe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top