mirror of
https://github.com/python/cpython.git
synced 2025-09-03 15:31:08 +00:00
Add support for negative indices in UserString.MutableString.__setitem__
and UserString.MutableString.__delitem__.
This commit is contained in:
parent
612df8e21d
commit
af3b39a182
3 changed files with 14 additions and 7 deletions
|
@ -146,9 +146,13 @@ class MutableString(UserString):
|
|||
def __hash__(self):
|
||||
raise TypeError, "unhashable type (it is mutable)"
|
||||
def __setitem__(self, index, sub):
|
||||
if index < 0:
|
||||
index += len(self.data)
|
||||
if index < 0 or index >= len(self.data): raise IndexError
|
||||
self.data = self.data[:index] + sub + self.data[index+1:]
|
||||
def __delitem__(self, index):
|
||||
if index < 0:
|
||||
index += len(self.data)
|
||||
if index < 0 or index >= len(self.data): raise IndexError
|
||||
self.data = self.data[:index] + self.data[index+1:]
|
||||
def __setslice__(self, start, end, sub):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue