<p dir="ltr"><br>
On 23 May 2013 16:37, "Devin Jeanpierre" <<a href="mailto:jeanpierreda@gmail.com">jeanpierreda@gmail.com</a>> wrote:<br>
><br>
> On Thu, May 23, 2013 at 2:04 AM, Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>> wrote:<br>
> > On Thu, 23 May 2013 12:12:26 +1000<br>
> > Nick Coghlan <<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>> wrote:<br>
> >> The binary operators can be more accurately said to use a complicated<br>
> >> single-dispatch dance rather than supporting native dual-dispatch.<br>
> ><br>
> > Not one based on the type of a single argument, though.<br>
><br>
> Why not?<br>
><br>
> I'd expect it to look something like this:<br>
><br>
>     @singledispatch<br>
>     def ladd(left, right):<br>
>         return NotImplemented<br>
><br>
>     @singledispatch<br>
>     def radd(right, left):<br>
>         return NotImplemented<br>
><br>
>     def add(left, right):<br>
>         x = ladd(left, right)<br>
>         if x is not NotImplemented:<br>
>             return x<br>
>         x = radd(right, left)<br>
>         if x is not NotImplemented:<br>
>             return x<br>
>         raise TypeError<br>
><br>
> Then instead of defining __add__ you define an overloaded<br>
> implementation of ladd, and instead of defining __radd__ you define an<br>
> overloaded implementation of radd.</p>
<p dir="ltr">That's the basic idea, but there's the extra complication that if type(right) is a strict subclass of type(left), you try radd first.</p>
<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> -- Devin<br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="http://mail.python.org/mailman/listinfo/python-dev">http://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">http://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
</p>