glom icon indicating copy to clipboard operation
glom copied to clipboard

When assigning, how to generate a different `missing` structure based on path type?

Open foucdeg opened this issue 2 years ago • 3 comments

Starting from an empty dict, I might make assignments like this:

glom.assign({}, "a.0.b", "value", missing=?)

The result I expect is the following:

{ 'a': [ { 'b': 'value' } ] }

although I understand that it could also be interpreted as

{ 'a': { '0': { 'b': 'value' } } }

This means that I want the missing function to create a list for the missing structure "a", and a dict for the missing structure "a.0". Unfortunately, missing isn't called with any arguments that would allow me to return a list or a dict depending on whether the next path part is an int or a string.

Is there some other way to do what I want?

foucdeg avatar Jul 23 '21 14:07 foucdeg

that's a great suggestion, providing arguments to missing

kurtbrose avatar Sep 26 '21 19:09 kurtbrose