Breaking convention with __or__/ __ror__ dunder methods
aviveh21 opened this issue · 3 comments
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_box
would 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)
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!
Looking good with or and ror methods. Thanks!
Added in 7.0.0