Hacker News new | ask | show | jobs
by geysersam 1385 days ago
I think he meant that for Python operators, the method can be dispatched based on the first or the second argument.
2 comments

Yes, this is a special case that Python implements for binary operators. When evaluating "a + b", if a.__add__(b) doesn't work, it'll try b.__radd__(a). See https://docs.python.org/3/reference/datamodel.html#object.__...
Yeah - `__add__` then `__radd__` isn't exactly double dispatch, but it's close. (There are corner cases involving inheritance where double-dispatch will work correctly but Python's approach will fail to pick the most-specific method.)
Yes, this is what I was referring to.