Skip to content

Commit

Permalink
Add update method for cogroups
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marshallward committed Jul 12, 2023
1 parent 5aa7f2b commit d65e593
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions f90nml/namelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit d65e593

Please sign in to comment.