On 23 May 2013 16:37, "Devin Jeanpierre" <jeanpierr...@gmail.com> wrote:
>
> On Thu, May 23, 2013 at 2:04 AM, Antoine Pitrou <solip...@pitrou.net>
wrote:
> > On Thu, 23 May 2013 12:12:26 +1000
> > Nick Coghlan <ncogh...@gmail.com> wrote:
> >> The binary operators can be more accurately said to use a complicated
> >> single-dispatch dance rather than supporting native dual-dispatch.
> >
> > Not one based on the type of a single argument, though.
>
> Why not?
>
> I'd expect it to look something like this:
>
>     @singledispatch
>     def ladd(left, right):
>         return NotImplemented
>
>     @singledispatch
>     def radd(right, left):
>         return NotImplemented
>
>     def add(left, right):
>         x = ladd(left, right)
>         if x is not NotImplemented:
>             return x
>         x = radd(right, left)
>         if x is not NotImplemented:
>             return x
>         raise TypeError
>
> Then instead of defining __add__ you define an overloaded
> implementation of ladd, and instead of defining __radd__ you define an
> overloaded implementation of radd.

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.

Cheers,
Nick.

>
> -- Devin
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
http://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to