summaryrefslogtreecommitdiff
path: root/comments.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-08-15 21:26:20 +0200
committerAnthon van der Neut <anthon@mnt.org>2018-08-15 21:26:20 +0200
commite14b468cdd14b4c19370bee96af50d1d788d4f6e (patch)
treeec5d0bbf08df764fe4ba14b04eee558d6166169c /comments.py
parentaaaebefa965eae325adf1bfd800d91765d89fb8b (diff)
downloadruamel.yaml-e14b468cdd14b4c19370bee96af50d1d788d4f6e.tar.gz
fix issue #221 .__add__() and .sort() no longer available on CommentedSeq0.15.57
CommentedSeq + list used to return a list, it now again does so. sort never worked correctly, it should now (i.e. move the EOL comments along). *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.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/comments.py b/comments.py
index 283a943..09ba705 100644
--- a/comments.py
+++ b/comments.py
@@ -492,6 +492,19 @@ class CommentedSeq(MutableSliceableSequence, CommentedBase):
self.copy_attributes(res, deep=True)
return res
+ def __add__(self, other):
+ return self._lst + other
+
+ def sort(self):
+ tmp_lst = sorted(zip(self._lst, range(len(self._lst))))
+ self._lst = [x[0] for x in tmp_lst]
+ itm = self.ca.items
+ self.ca._items = {}
+ for idx, x in enumerate(tmp_lst):
+ old_index = x[1]
+ if old_index in itm:
+ self.ca.items[idx] = itm[old_index]
+
class CommentedKeySeq(tuple, CommentedBase):
"""This primarily exists to be able to roundtrip keys that are sequences"""