From ad245940e37c3169e990704c7b7a51813f48f8a8 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Tue, 22 Sep 2020 08:29:17 +0200 Subject: fix issue 359 --- README.rst | 4 ++++ comments.py | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index f757911..b66d249 100644 --- a/README.rst +++ b/README.rst @@ -54,6 +54,10 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +NEXT: + - fix for issue 359: could not update() CommentedMap with keyword arguments + (reported by `Steve Franchak __) + 0.16.12 (2020-09-04): - update links in doc diff --git a/comments.py b/comments.py index 1cfd662..d00cf0d 100644 --- a/comments.py +++ b/comments.py @@ -696,20 +696,22 @@ class CommentedMap(ordereddict, CommentedBase): # type: ignore self.ca.comment[1] = pre_comments return pre_comments - def update(self, vals): - # type: (Any) -> None + def update(self, *vals, **kw): + # type: (Any, Any) -> None try: - ordereddict.update(self, vals) + ordereddict.update(self, *vals, **kw) except TypeError: # probably a dict that is used - for x in vals: - self[x] = vals[x] + for x in *vals: + self[x] = *vals[x] try: - self._ok.update(vals.keys()) # type: ignore + self._ok.update(*vals.keys()) # type: ignore except AttributeError: # assume a list/tuple of two element lists/tuples - for x in vals: + for x in *vals: self._ok.add(x[0]) + if kw: + self._ok.add(*kw.keys()) def insert(self, pos, key, value, comment=None): # type: (Any, Any, Any, Optional[Any]) -> None -- cgit v1.2.1