[Python-bugs-list] [ python-Bugs-473985 ] str, getitem and slices (original) (raw)
noreply@sourceforge.net noreply@sourceforge.net
Tue, 23 Oct 2001 07:05:03 -0700
- Previous message: [Python-bugs-list] [ python-Bugs-473985 ] str, __getitem__ and slices
- Next message: [Python-bugs-list] [ python-Bugs-474077 ] 2.2b1: Error compiling extns with BCC
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Bugs item #473985, was opened at 2001-10-23 03:39 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=473985&group_id=5470
Category: None Group: None Status: Open Resolution: Invalid Priority: 5 Submitted By: Walter D�rwald (doerwalter) Assigned to: Nobody/Anonymous (nobody) Summary: str, getitem and slices
Initial Comment: Using slices with getitem doesn't work with classes derived from str:
class S(str): def getitem(self, index): print "getitem", index return str.getitem(self, index) def setitem(self, index, value): print "setitem", index, value
s = S("foo") print s[0] print s[0:2] s[0] = "b" s[0:2] = "bar"
This prints:
getitem 0 f fo setitem 0 b setitem slice(0, 2, None) bar
instead of
getitem 0 f getitem slice(0, 2, None) fo setitem 0 b setitem slice(0, 2, None) bar
i.e. when no getslice is defined s[0:2] will not be forwarded to getitem, but it seems to work for setitem.
Comment By: Walter D�rwald (doerwalter) Date: 2001-10-23 07:05
Message: Logged In: YES user_id=89016
Oops, this wasn't meant to be a patch. Should have gone into the bugs category.
The problems is that http://python.sourceforge.net/devel- docs/ref/sequence-methods.html says, that getslice is "Deprecated since release 2.0", so the user will want to implement getslice via getitem.
Comment By: Guido van Rossum (gvanrossum) Date: 2001-10-23 06:48
Message: Logged In: YES user_id=6380
I don't think this is a bug. S inherits getslice from the str base class, but since str is immutable, it doesn't define a setslice to inherit for S.
BTW I'm reclassifying this as a bug, not a patch. This will unfortunately invalidate the old URL you had for this entry (SF doesn't really like reclassification that much.)
You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=473985&group_id=5470
- Previous message: [Python-bugs-list] [ python-Bugs-473985 ] str, __getitem__ and slices
- Next message: [Python-bugs-list] [ python-Bugs-474077 ] 2.2b1: Error compiling extns with BCC
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]