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

Treat None values as unexisting keys for default_box #59

Closed
eMerzh opened this issue Sep 29, 2018 · 7 comments
Closed

Treat None values as unexisting keys for default_box #59

eMerzh opened this issue Sep 29, 2018 · 7 comments
Milestone

Comments

@eMerzh
Copy link

eMerzh commented Sep 29, 2018

Hi,

thanks a lot for your project, it's currently helping me a lot :)
one feature i missed is the ability to treat None values as if there was no key defined.

like in this example.

b=Box({'brol': None}, default_box=True)
b.brol.truc

gives

Traceback (most recent call last):
File "", line 1, in
AttributeError: 'NoneType' object has no attribute 'truc'

but this works as exepected

b=Box({}, default_box=True)
b.brol.truc

many many thanks 👍

@eMerzh eMerzh changed the title Treat None values as unexisting keys Treat None values as unexisting keys for default_box Sep 29, 2018
@cdgriffith
Copy link
Owner

Hi @eMerzh , sorry for delay getting back. That could be an interesting feature to add, I will look into the effort for it when I get a chance (feel free to put in a PR as well.)

I have a few major life events happening / coming up, so I won't be available to contribute a good amount of time until after Thanksgiving or so as a forewarning.

@haruntuncay
Copy link

Hello @cdgriffith, if you are open to contributions, can I submit a PR for this issue ?

@cdgriffith
Copy link
Owner

Hi @haruntuncay I am always open to ideas and improvements!

For this specifically as it changes current behavior it will need to target next major release, so if you do create it please do it off of the 4.0 branch. Thanks!

@haruntuncay
Copy link

@cdgriffith , I was going to give this issue a shot today, and wanted to ask for your opinion on whether this behavior should be configurable or not when a default_box is used ? For example, a config option might be:
b = Box({'brol': None}, default_box=True, ignore_none_values=True) , or it could just be as if that key never existed. Which do you think is more appropriate ?

@cdgriffith
Copy link
Owner

@haruntuncay I think I like the idea of making this new feature the default behavior, but do have an option to opt out of it as there may be cases it to be compatible with the previous behavior. So maybe default_box_none_transform=True or something?

@haruntuncay
Copy link

Okay, I will update the PR accordingly. Are we set on default_box_none_transform as the name of the config option ?

@cdgriffith cdgriffith added this to the 4.0 milestone Oct 22, 2019
@cdgriffith
Copy link
Owner

Added in 4.0

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

No branches or pull requests

3 participants