From d65e593ab70e61d90bb0f1ec1ed4f6bb3551b9ad Mon Sep 17 00:00:00 2001 From: Marshall Ward Date: Wed, 12 Jul 2023 15:33:35 -0400 Subject: [PATCH] Add update method for cogroups Cogroups, although subclasses of lists, are designed to behave as dicts in many situations. One absence is the support of certain intrinsic methods. The `patch` method of `Namelist` relied on `update`, but this was not supported by Cogroups and would raise an error if one was returned. This patch adds support to Cogroups. It does not address which elements of the Cogroup should receive the patch. Currently, all elements in the cogroup are patched. This is sufficient to avoid errors, but should be addressed in the future. --- f90nml/namelist.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/f90nml/namelist.py b/f90nml/namelist.py index 879fdce..7fcd4ec 100644 --- a/f90nml/namelist.py +++ b/f90nml/namelist.py @@ -1061,6 +1061,13 @@ def __delitem__(self, index): # Finally, remove from this list super(Cogroup, self).__delitem__(index) + def update(self, args): + if isinstance(args, dict): + for key in self.keys: + self.nml[key].update(args) + else: + raise NotImplementedError + @property def keys(self): """Return the namelist keys in the cogroup."""