diff --git a/mwparserfromhell/smart_list.py b/mwparserfromhell/smart_list.py index 062e9ad..46c475a 100644 --- a/mwparserfromhell/smart_list.py +++ b/mwparserfromhell/smart_list.py @@ -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: diff --git a/tests/test_smart_list.py b/tests/test_smart_list.py index 777660a..10e39ea 100644 --- a/tests/test_smart_list.py +++ b/tests/test_smart_list.py @@ -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"""