summaryrefslogtreecommitdiff
path: root/comments.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-08-14 17:53:12 +0200
committerAnthon van der Neut <anthon@mnt.org>2018-08-14 17:53:12 +0200
commitecd5f8dbaf580fa618205845374256a301d0675f (patch)
treec90362a9922031e9fdf49a3dcfaabe8291e337b5 /comments.py
parent0923c2a691f57f9e095f5c4b9a8f06fa78bb46d2 (diff)
downloadruamel.yaml-ecd5f8dbaf580fa618205845374256a301d0675f.tar.gz
fix issue #176 CommentedSeq does not support slice assignment
I implemented slicing in an intermediate baseclass ruamel.yaml.compat.MutableSliceableSequence, on top of collections.{,abc.}.MutableSequence. I'm not sure if I tested all possibilities but CommentedSeq **should** now support all (extended) slicing operations. Test were added in _test/test_issues.py *When this change indeed resolves your problem, please **Close** this issue*. *(You can do so using the WorkFlow pull-down (close to the top right of this page))*
Diffstat (limited to 'comments.py')
-rw-r--r--comments.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/comments.py b/comments.py
index 2063775..283a943 100644
--- a/comments.py
+++ b/comments.py
@@ -12,7 +12,7 @@ import sys
import copy
-from ruamel.yaml.compat import ordereddict, PY2, string_types, MutableSequence
+from ruamel.yaml.compat import ordereddict, PY2, string_types, MutableSliceableSequence
from ruamel.yaml.scalarstring import ScalarString
if PY2:
@@ -385,18 +385,18 @@ class CommentedBase(object):
raise NotImplementedError
-class CommentedSeq(MutableSequence, CommentedBase):
+class CommentedSeq(MutableSliceableSequence, CommentedBase):
__slots__ = (Comment.attrib, '_lst')
def __init__(self, *args, **kw):
# type: (Any, Any) -> None
self._lst = list(*args, **kw)
- def __getitem__(self, idx):
+ def __getsingleitem__(self, idx):
# type: (Any) -> Any
return self._lst[idx]
- def __setitem__(self, idx, value):
+ def __setsingleitem__(self, idx, value):
# type: (Any, Any) -> None
# try to preserve the scalarstring type if setting an existing key to a new value
if idx < len(self):
@@ -408,7 +408,7 @@ class CommentedSeq(MutableSequence, CommentedBase):
value = type(self[idx])(value)
self._lst.__setitem__(idx, value)
- def __delitem__(self, idx=None):
+ def __delsingleitem__(self, idx=None):
# type: (Any) -> Any
del self._lst[idx]
self.ca.items.pop(idx, None) # might not be there -> default value