3 ms·
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 htt
by csande17 4y 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.__radd__ https://docs.python.org/3/reference/datamodel.html#object.__...
- pansa2 4y agoYeah - `__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.)