cdgriffith / Box

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

frozen_box propagation into sub-nodes #150

Closed ipcoder closed 4 years ago

ipcoder commented 4 years ago

Is that a designed behaviour:

hash(Box({'x': {'y': 2}}, frozen_box=True))
# OK!

hash(Box({'x': Box({'y': 2})}, frozen_box=True))
# TypeError: unhashable type: 'Box'

When combining a structure from pieces a mixed dict/Box hierarchy may emerge, and to make it frozen one should now traverse it and change box-node by node, or some ugly thing like that:

frozen_box = Box(Box(struct).to_dict(), frozen_box=True)

An alternative would be to make sure that Box(struct, frozen_box=True) would make sure all the sub-boxes are frozen too.

What do you think? Thanks

cdgriffith commented 4 years ago

Well that's something I guess I never thought about was propagating the settings to already created sub-boxes.

It would make sense that all box objects coming into another box should adhere to the parents convention. However I can also see where some might find that detrimental, so it will have to be configurable (probably with auto inheritance being the standard.)

This is something I will want to flush out for 5.0

cdgriffith commented 4 years ago

I am starting to cut pre-releases for 5.0.0, if you are feeling adventurous please test it out and let me know if it solves your issues!

pip install --upgrade "python-box[all]>=5.0.0a0"

Details on the new wiki