Y
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
csande17
1385 days ago
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.__...
link
pansa2
1385 days ago
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.)
link
munificent
1385 days ago
Yes, this is what I was referring to.
link