From e14b468cdd14b4c19370bee96af50d1d788d4f6e Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Wed, 15 Aug 2018 21:26:20 +0200 Subject: fix issue #221 .__add__() and .sort() no longer available on CommentedSeq 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))* --- comments.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'comments.py') 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""" -- cgit v1.2.1