launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25054
[Merge] ~cjwatson/launchpad:py3-limitedlist into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-limitedlist into launchpad:master.
Commit message:
Fix LimitedList for Python 3
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/387707
The slice protocol is a bit different, as is one exception message.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-limitedlist into launchpad:master.
diff --git a/lib/lp/services/doc/limitedlist.txt b/lib/lp/services/doc/limitedlist.txt
index 4abd0a0..10f1fed 100644
--- a/lib/lp/services/doc/limitedlist.txt
+++ b/lib/lp/services/doc/limitedlist.txt
@@ -16,7 +16,7 @@ The property max_length stores the maximum allowed length of the list.
>>> LimitedList()
Traceback (most recent call last):
...
- TypeError: __new__() takes at least 2 arguments (1 given)
+ TypeError: __new__() ...
We can optionally specify the initial content of the sequence. Note that
only the last N elements of the second parameter are stored, where N is
diff --git a/lib/lp/services/limitedlist.py b/lib/lp/services/limitedlist.py
index 5033df7..ea340b9 100644
--- a/lib/lp/services/limitedlist.py
+++ b/lib/lp/services/limitedlist.py
@@ -30,7 +30,7 @@ class LimitedList(list):
"""Ensure that the maximum length is not exceeded."""
elements_to_drop = self.__len__() - self.max_length
if elements_to_drop > 0:
- self.__delslice__(0, elements_to_drop)
+ del self[0:elements_to_drop]
def __add__(self, other):
return LimitedList(
@@ -56,6 +56,12 @@ class LimitedList(list):
self._ensureLength()
return result
+ def __setitem__(self, key, value):
+ result = super(LimitedList, self).__setitem__(key, value)
+ if isinstance(key, slice):
+ self._ensureLength()
+ return result
+
def __setslice__(self, i, j, sequence):
result = super(LimitedList, self).__setslice__(i, j, sequence)
self._ensureLength()