Mercurial > cpython-lru_cache-weakref
diff Lib/UserString.py @ 34614:ac6dfc67c77f legacy-trunk
Add support for negative indices in UserString.MutableString.__setitem__
and UserString.MutableString.__delitem__.
| author | Walter Dörwald <walter@livinglogic.de> |
|---|---|
| date | Fri, 18 Feb 2005 13:22:43 +0000 |
| parents | b56481a90519 |
| children | 4eaab38566c9 |
line wrap: on
line diff
--- a/Lib/UserString.py Fri Feb 18 11:54:46 2005 +0000 +++ b/Lib/UserString.py Fri Feb 18 13:22:43 2005 +0000 @@ -146,9 +146,13 @@ 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):
