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

default_box does not work with box_dots #192

Closed
Rexbard opened this issue Mar 11, 2021 · 5 comments
Closed

default_box does not work with box_dots #192

Rexbard opened this issue Mar 11, 2021 · 5 comments

Comments

@Rexbard
Copy link

Rexbard commented Mar 11, 2021

This behaviour is noted in the Wiki, but I don't agree it is as it should be.

Using default_box, one can create and modify a new dotted chain as expected:

>>> b=Box(default_box=True)
>>> b.a.b.c = 1
>>> print(b)
<Box: {'a': {'b': {'c': 1}}}>
>>> b["a.b.c"] = 2
>>> print(b)
<Box: {'a': {'b': {'c': 2}}}>

However, when trying to create a new value using box_dots, it does not work as I expect (again the demonstrated behavior is noted in the Wiki).

>>> b=Box(default_box=True, box_dots=True)
>>> b["a.b.c"] = 1
>>> print(b)
<Box: {'a.b.c': 1}>

By declaring box_dots=True the programmer has explicitly stated they want to interpret the periods as field separators. It seems that the above code should return the same as the first code block.

Since I require this behavior, I have to split the index string and create empty boxes, then perform the b["a.b.c"]=1 for it to work as intended.

@cdgriffith
Copy link
Owner

To be honest it would probably be a lot easier programmatically to say that everything with dots is always changed for box dots.

Such a breaking change would require a major version bump (which I am not against), but also not something I have the cycles to work on myself.

@ipcoder
Copy link

ipcoder commented May 25, 2021

Is this a related problem?

>>> b = Box(box_dots=True)
>>> b['x'] = {'y':10}
<Box: {'x': {'y': 10}}>
>>> b.setdefault('x.y', 20)
<Box: {'x': {'y': 20}}>

That is setdefault overwrites already defined value.

@cdgriffith
Copy link
Owner

Sorry I missed this earlier @ipcoder, that is actually an unrelated issue, addressing in 5.4.0

Basically the issue is that I was doing a check of key in self, but in uses __iter__ so it doesn't see the sub box dots keys, and doesn't think it exists, so it overwrites it.

cdgriffith added a commit that referenced this issue Feb 14, 2022
… variable on get request (thanks to ipcoder)

* Changing #123 box_dots to convert ints and bytes as needed (thanks to Marcelo Huerta)
* Changing #192 box_dots and box_default to split and create sub dictionaries as needed for insertion (thanks to Rexbard)
cdgriffith added a commit that referenced this issue Jan 28, 2023
…te keys (thanks to Rexbard)

* Adding #236 iPython detection to prevent adding attribute lookup words (thanks to Nishikant Parmar)
* Adding new DDBox class (Default Dots Box) that is a subclass of SBox
@cdgriffith
Copy link
Owner

Adding this feature in Box 7! Please test and give feedback if possible pip install python-box[all]~=7.0.0rc0

box_dots now means all periods should be split!

cdgriffith added a commit that referenced this issue Feb 4, 2023
* Adding #169 default functions with the box_instance and key parameter (thanks to Коптев Роман Викторович)
* Adding #170 Be able to initialize with a flattened dict - by using DDBox (thanks to Ash A.)
* Adding #192 box_dots treats all keys with periods in them as separate keys (thanks to Rexbard)
* Adding #211 support for properties and setters in subclasses (thanks to Serge Lu and David Aronchick)
* Adding #226 namespace to track changes to the box (thanks to Jacob Hayes)
* Adding #236 iPython detection to prevent adding attribute lookup words (thanks to Nishikant Parmar)
* Adding #238 allow ``|`` and ``+`` for frozen boxes (thanks to Peter B)
* Adding new DDBox class (Default Dots Box) that is a subclass of SBox
* Fixing #235 how ``|`` and ``+`` updates were performed for right operations (thanks to aviveh21)
* Fixing #234 typos (thanks to Martin Schorfmann)
* Fixing no implicit optionals with type hinting
@cdgriffith
Copy link
Owner

Added in 7.0.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