[Patches] [ python-Patches-473985 ] str, __getitem__ and slices
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 23 Oct 2001 03:39:14 -0700
Patches item #473985, was opened at 2001-10-23 03:39
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=473985&group_id=5470
Category: Core (C code)
Group: None
Status: Open
Resolution: None
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__.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=473985&group_id=5470