Przeglądaj źródła

Squash a bug dealing with extended slices.

tags/v0.2
Ben Kurtovic 11 lat temu
rodzic
commit
b298a68b37
2 zmienionych plików z 9 dodań i 8 usunięć
  1. +6
    -5
      mwparserfromhell/smart_list.py
  2. +3
    -3
      tests/test_smart_list.py

+ 6
- 5
mwparserfromhell/smart_list.py Wyświetl plik

@@ -87,8 +87,9 @@ class SmartList(list):
return super(SmartList, self).__setitem__(key, item)
item = list(item)
super(SmartList, self).__setitem__(key, item)
key = slice(key.start or 0, maxsize if key.stop is None else key.stop)
diff = len(item) - key.stop + key.start
keystop = maxsize if key.stop is None else key.stop
key = slice(key.start or 0, keystop, key.step or 1)
diff = len(item) + (key.start - key.stop) / key.step
values = self._children.values if py3k else self._children.itervalues
if diff:
for child, (start, stop, step) in values():
@@ -101,10 +102,10 @@ class SmartList(list):
super(SmartList, self).__delitem__(key)
if isinstance(key, slice):
keystop = maxsize if key.stop is None else key.stop
key = slice(key.start or 0, keystop)
key = slice(key.start or 0, keystop, key.step or 1)
else:
key = slice(key, key + 1)
diff = key.stop - key.start
key = slice(key, key + 1, 1)
diff = (key.stop - key.start) / key.step
values = self._children.values if py3k else self._children.itervalues
for child, (start, stop, step) in values():
if start > key.start:


+ 3
- 3
tests/test_smart_list.py Wyświetl plik

@@ -306,9 +306,9 @@ class TestSmartList(unittest.TestCase):
"""make sure _ListProxy's getitem/setitem/delitem work"""
self._test_get_set_del_item(lambda L: SmartList(list(L))[:])
self._test_get_set_del_item(lambda L: SmartList([999] + list(L))[1:])
# self._test_get_set_del_item(lambda L: SmartList(list(L) + [999])[:-1])
# builder = lambda L: SmartList([101, 102] + list(L) + [201, 202])[2:-2]
# self._test_get_set_del_item(builder)
self._test_get_set_del_item(lambda L: SmartList(list(L) + [999])[:-1])
builder = lambda L: SmartList([101, 102] + list(L) + [201, 202])[2:-2]
self._test_get_set_del_item(builder)

def test_child_add(self):
"""make sure _ListProxy's add/radd/iadd work"""


Ładowanie…
Anuluj
Zapisz