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

frozen_box propagation into sub-nodes #150

Closed
ipcoder opened this issue Apr 10, 2020 · 2 comments · Fixed by #145
Closed

frozen_box propagation into sub-nodes #150

ipcoder opened this issue Apr 10, 2020 · 2 comments · Fixed by #145

Comments

@ipcoder
Copy link

ipcoder commented Apr 10, 2020

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
Copy link
Owner

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 added a commit that referenced this issue Apr 21, 2020
…ks to David Aronchick)

* Adding new parameter `box_inherent_settings` #150 (thanks to ipcoder)
cdgriffith added a commit that referenced this issue Apr 26, 2020
…ttings and copy objects #150 (thanks to ipcoder)

* Changing `BoxList.box_class` to be stored in `BoxList.box_options` dict as `box_class`
* Removing support for single level circular references
@cdgriffith
Copy link
Owner

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

cdgriffith added a commit that referenced this issue Jul 12, 2020
* Adding support for msgpack converters `to_msgpack` and `from_msgpack`
* Adding support for comparision of `Box` to other boxes or dicts via the `-` sub operator #144 (thanks to Hitz)
* Adding support to `|` union boxes like will come default in Python 3.9 from PEP 0584
* Adding `mypy` type checking, `black` formatting and other checks on commit
* Adding new parameter `box_class` for cleaner inheritance #148 (thanks to David Aronchick)
* Adding `dotted` option for `keys` method to return box_dots style keys (thanks to ipcoder)
* Fixing box_dots to properly delete items from lists
* Fixing box_dots to properly find items with dots in their key
* Fixing that recast of subclassses of `Box` or `BoxList` were not fed box properties (thanks to Alexander Kapustin)
* Changing that sub boxes are always created to properly propagate settings and copy objects #150 (thanks to ipcoder)
* Changing that default_box will not raise key errors on `pop` #67 (thanks to Patrock)
* Changing `to_csv` and `from_csv` to have same string and filename options as all other transforms
* Changing back to no required external imports, instead have extra requires like [all] (thanks to wim glenn)
* Changing from putting all details in README.rst to a github wiki at https://github.com/cdgriffith/Box/wiki
* Changing `BoxList.box_class` to be stored in `BoxList.box_options` dict as `box_class`
* Changing `del` will raise `BoxKeyError`, subclass of both `KeyError` and `BoxError`
* Removing support for single level circular references
* Removing readthedocs generation
* Removing overrides for `keys`, `values` and `items` which will return views again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants