On Wed, Jun 5, 2019 at 11:31 AM Chris Angelico email@example.com wrote:
Part of the reason you can't just treat the + operator as a method call is that there are reflected methods. Consider:
class Int(int): def __radd__(self, other): print("You're adding %s to me!" % other) return 1234
x = Int(7) print(x + 1) print(1 + x)
If these were implemented as x.__add__(1) and (1).__add__(x), the second one would use the default implementation of addition. The left operand would be the only one able to decide how something should be implemented.
Yep, just did an experiment in Scala, where you can do x + 1, but not 1 + x. So it looses some flexibility in terms of how you write your expression, but still, it looks OK to only write x + 1 and when you write 1 + x you get an error immediately.