cdgriffith / Box

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

Breaking convention with __or__/ __ror__ dunder methods #235

Closed aviveh21 closed 1 year ago

aviveh21 commented 1 year ago

Hi,

An __or__ method is not meant to be cumulative, as we know. In box-box operations new_box = box_1 | box_2 , everything is working properly That said, new_boxwould be different if we would write new_box = box_2 | box_1

The same is with dictionaries ( as introduced in PEP 584), and dict-dict operations.

The problem starts when you combine Box with a dict in an __or__/__ror__ method, for example new_box = box_1 | dict_1.

You can check that:

new_box1 = box_1 | dict_1 , new_box2 = dict_1 | box_1

And you get that - new_box1 **==** new_box2

As opposed to the noncumulative attribute of OR operation in Dicts and Boxes.

If you would make the change: new_box1 = box_1 | Box(dict_1) , new_box2 = Box(dict_1) | box_1

you would get - new_box1 **!=** new_box2.

But that means that you can't do box operations with normal dicts (at least with OR dunder method)

cdgriffith commented 1 year ago

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

Thank you for pointing this out!

aviveh21 commented 1 year ago

Looking good with or and ror methods. Thanks!

cdgriffith commented 1 year ago

Added in 7.0.0