[Python-Dev] PEP 443 - Single-dispatch generic functions

Paul Moore p.f.moore at gmail.com
Thu May 23 17:11:08 CEST 2013


On 23 May 2013 15:58, Łukasz Langa <lukasz at langa.pl> wrote:

> On 23 maj 2013, at 16:49, Guido van Rossum <guido at python.org> wrote:
>
> > Łukasz, are there any open issues? Otherwise I'm ready to accept the PEP.
>
> There's one. Quoting the PEP:
>
> "The dispatch type is currently specified as a decorator argument. The
> implementation could allow a form using argument annotations. This usage
> pattern is out of scope for the standard library (per PEP 8). However,
> whether this registration form would be acceptable for general usage, is
> up to debate."
>
> I feel that the PEP should explicitly allow or disallow for the
> implementation to accept dispatch on annotations, e.g.:
>
> @func.register
> def _(arg: int):
>   ...
>
> versus
>
> @func.register(int)
> def _(arg):
>   ...


Personally, I think the register(int) form seems more natural. But that may
well be because there are no uses of annotations in the wild (at least not
in code I'm familiar with) and having this as an example of how annotations
can be used would help with adoption.

I'm not 100% sure what the options are.

1. Only support the register(int) form
2. Only support the annotation form
3. Support both annotation and argument forms

Is the debate between 1 and 2, or 1 and 3? Is it even possible to implement
3 without having 2 different names for "register"?

If the debate is between 1 and 2, I'd prefer 1. But if it's between 1 and
3, I'm less sure - having the *option* to try annotations for this in my
own code sounds useful.

Paul.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130523/5331e932/attachment.html>


More information about the Python-Dev mailing list