From 88dd69ffa8ed0fd9f66fc7074a785ba21706bb4d Mon Sep 17 00:00:00 2001 From: Kurt Rose Date: Thu, 17 Oct 2019 10:25:35 -0700 Subject: [PATCH] first at at Update glom --- glom/mutation.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/glom/mutation.py b/glom/mutation.py index cd24ef10..4c936477 100644 --- a/glom/mutation.py +++ b/glom/mutation.py @@ -179,6 +179,23 @@ def glomit(self, target, scope): return target +class Update(object): + """ + Update a dict or set without otherwise modifying. + This allows dict creation to be broken into "chunks". + + ({'a': 'a'}, [dict, Update({'b': 'b', 'c': 'c'})]) + """ + def __init__(self, subspec): + assert type(subspec) in (dict, set, frozenset) + self.subspec = subspec + + def glomit(self, target, scope): + assert hasattr(target, 'update') + target.update(scope[glom](target, self.subspec, scope)) + return target + + def assign(obj, path, val, missing=None): """The ``assign()`` function provides convenient "deep set" functionality, modifying nested data structures in-place::