473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why is __getslice__ still implemented?

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
<news:ma**************************************@pyt hon.org>, this may
have efficiency reasons, however, I agree with
news:11**********************@f14g2000cwb.googlegr oups.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.

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: br*****@jabber.org
(See http://ime.webhop.org for ICQ, MSN, etc.)
Apr 10 '07 #1
5 1934
Torsten Bronger wrote:
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
<news:ma**************************************@pyt hon.org>, this may
have efficiency reasons, however, I agree with
news:11**********************@f14g2000cwb.googlegr oups.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.

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.
pyclass Bob(object):
.... def __getitem__(self, *args):
.... print args
....
pyb = Bob()
pyb[4:21:2]
(slice(4, 21, 2),)
pyb[5:18:21,2:9:2,8,14:4]
((slice(5, 18, 21), slice(2, 9, 2), 8, slice(14, 4, None)),)
Apr 10 '07 #2
Hallöchen!

James Stroud writes:
[...]

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.
pyclass Bob(object):
This should be Bob(unicode).
... def __getitem__(self, *args):
... print args
...
pyb = Bob()
pyb[4:21:2]
(slice(4, 21, 2),)
pyb[5:18:21,2:9:2,8,14:4]
((slice(5, 18, 21), slice(2, 9, 2), 8, slice(14, 4, None)),)
Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: br*****@jabber.org
(See http://ime.webhop.org for ICQ, MSN, etc.)
Apr 10 '07 #3
Torsten Bronger wrote:
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
<news:ma**************************************@pyt hon.org>, this may
have efficiency reasons, however, I agree with
news:11**********************@f14g2000cwb.googlegr oups.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:

http://sourceforge.net/tracker/?grou...70&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
Apr 10 '07 #4
Hallöchen!

Steven Bethard writes:
Torsten Bronger wrote:
>[...]

[...] 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/?grou...70&atid=105470
Done.

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: br*****@jabber.org
(See http://ime.webhop.org for ICQ, MSN, etc.)
Apr 10 '07 #5
Torsten Bronger wrote:
Hallöchen!

Steven Bethard writes:
>Torsten Bronger wrote:
>>[...]

[...] 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/?grou...70&atid=105470

Done.
Thanks!

STeVe
Apr 10 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Fernando Perez | last post by:
Hi all, I was wondering if someone can help me understand why __getslice__ has been deprecated, yet it remains necessary to implement it for simple slices (i:j), while __getitem__ gets called...
1
by: Dave Huang | last post by:
Hi, I don't actually know Python; I'm just trying to debug a problem I encounted in another program, so apologies if this has been covered before. I did do some Google searches though, and didn't...
6
by: Chris Dunaway | last post by:
I have a simple interface with two methods, MethodA, and MethodB. I also have a class with implements the interface. The class provides a full implementation for MethodA but for special reasons,...
3
by: lodge.stuart | last post by:
Hi I've written a small AJAX-style UI - although it's not strictly AJAX as it uses HTML fragments rather than XML This UI works fine for me and the majority of users. However, a few users...
6
by: Boaz Ben-Porat | last post by:
I heard somewhere that the DataGrid class is implemented as a XML graph in memory. Is this true ? TIA Boaz Ben-Porat DataPharm a/s Denmark
4
by: m96 | last post by:
hi, i'm trying to make a query to a ldap server (version v2 or v3 doen't matter) with c#. the query works just fine but the problem is that i can't read the custom attributes/fields, since .net...
4
by: dba123 | last post by:
I took the code from here and tweaked it to our needs. One of the methods is erroring out throwing an exception and I'm not sure why: object IConfigurationSectionHandler.Create(object parent,...
2
by: Screamingfirst | last post by:
If __getslice__ is depreciated (since version 2.0) why are neither __setslice__ or __delslice__ depreciated? http://docs.python.org/ref/sequence-methods.html
12
by: Author | last post by:
I know the basic differences between a struct and a class, but apparently not good enough to know why some types/concepts are implemented as struct whereas most types are implemented as class. For...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.