sub, rsub and isub
See original GitHub issueI’d propose a behavior change of the __sub__ operator to align with how the other operators work. Right now v - w will do the equivalent of v + (-w) where the neg takes the inverse of w. I think it should align instead with what __add__ does and use v.eadd(w, add_op=MINUS). The old behavior can still be had by adding the negation. This makes all the binary operations consistent, and allows me to make a scalar construction like w - 5 which would become w.apply_second(MINUS, 5). Any thoughts @szarnyasg and @marci543 ? I made a PR #69.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
What is a typical instance of using '__rsub__' method in Python?
__rsub__(x) is called if x.__sub__(y) returns NotImplemented . I can't picture why the method is necessary and how exactly it is used in ......
Read more >Python __isub__() Magic Method - Finxter
Syntax. object.__isub__(self, other). The Python __isub__() magic method implements in-place subtraction x -= y that subtracts the operands from each other ...
Read more >9. Magic Methods | OOP | python-course.eu
There is a special (or a "magic") method for every operator sign. The magic method for the "+" sign is the __add__ method....
Read more >Is the result of sub() and rsub() the same? Why/why not?
Ans: No the result of sub() and rsub() is not same because performing subtraction on two different operands in different order can produce...
Read more >OperatorHook - Python Wiki
... += 1: __iadd__ op-1: __sub__ 1-op: __rsub__ op -= 1: __isub__ op*1: ... print '__rsub__', def __isub__(self, other): print '__isub__',; ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

And you know, the more I think about it,
+and*maybe aren’t the best map toeWiseAddandeWiseMultwhich are really much more like&(union) and|(intersection) operations that just happen to default to plus and times operations and the actual math operations are just nice shortcuts toeaddwith fixed operations. Maybe I’m overthinking it.As we discussed all math operators are now
A.eadd(B)with the appropriate binary operator. I’ll address the possibility of union and intersection operators in another issue.