Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
foucdeg opened this issue Jul 23, 2021 · 3 comments

Comments

@foucdeg
Copy link

foucdeg commented Jul 23, 2021

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 foucdeg changed the title when assigning, how to ggenerate a different missing structure based on path type? When assigning, how to generate a different missing structure based on path type? Jul 26, 2021
@kurtbrose
Copy link
Collaborator

that's a great suggestion, providing arguments to missing

@Kwill3
Copy link

Kwill3 commented Feb 20, 2024

Here to bump this issue and check if any progress has been made on this? Otherwise is there another way we can assign between lists and dicts on current version?

@mahmoud
Copy link
Owner

mahmoud commented Mar 23, 2024

@Kwill3 we haven't really done anything with this. I think everyone's open to the idea, though.

I guess the next step in the conversation is to ask what arguments would be useful? We could pass the current path, the current glom scope (possibly too technical for day-to-day use), just the name of the current field, etc.?

A really cool thing would be to create one's own spec type (forked from Assign) and experiment, if you'd like to help advance the feature. Docs on spec type creation are here: https://glom.readthedocs.io/en/latest/custom_spec_types.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants