-
Notifications
You must be signed in to change notification settings - Fork 112
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
Breaking convention with __or__/ __ror__ dunder methods #235
Labels
Comments
Merged
Adding this feature in Box 7! Please test and give feedback if possible Thank you for pointing this out! |
Looking good with or and ror methods. Thanks! |
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
Added in 7.0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 properlyThat said,
new_box
would be different if we would writenew_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)
The text was updated successfully, but these errors were encountered: