cdgriffith / Box

Python dictionaries with advanced dot notation access
https://github.com/cdgriffith/Box/wiki
MIT License
2.61k stars 106 forks source link

default_box_create_on_get=False should still create keys on assigment #274

Open wrdls opened 4 months ago

wrdls commented 4 months ago

As reported before in https://github.com/cdgriffith/Box/issues/164#issuecomment-1359179014

The current behavior of default_box_create_on_get is not what you would expect and eliminates a large part what makes default_box useful in the first place.

In the following case I would still expect b.foo.bar to be set to 1.

>>> b = Box(default_box=True, default_box_create_on_get=False)
>>> b.foo.bar
Box({})
>>> b.foo.bar = 1
>>> b.foo.bar
Box({})
>>> b
Box({})

Not sure if this is feasible, but a new config option default_box_create_on_set could be added to control this behavior.