diff options
| author | Walter Dörwald <walter@livinglogic.de> | 2005-02-18 13:22:43 +0000 |
|---|---|---|
| committer | Walter Dörwald <walter@livinglogic.de> | 2005-02-18 13:22:43 +0000 |
| commit | 18490233770a0b6c1c5ae282b022123bebc2de97 (patch) | |
| tree | 59d68eb36a0e78cded52849957e8c7800523749a /Lib/UserString.py | |
| parent | e2db6cafed8d2b8dafb59c94e997512d927d1038 (diff) | |
| download | cpython-18490233770a0b6c1c5ae282b022123bebc2de97.tar.gz | |
Add support for negative indices in UserString.MutableString.__setitem__
and UserString.MutableString.__delitem__.
Diffstat (limited to 'Lib/UserString.py')
| -rwxr-xr-x | Lib/UserString.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/UserString.py b/Lib/UserString.py index e8e0fedd87..3251139050 100755 --- a/Lib/UserString.py +++ b/Lib/UserString.py @@ -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): |
