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

Nick Coghlan ncoghlan at gmail.com
Fri May 24 13:41:27 CEST 2013


On Fri, May 24, 2013 at 8:53 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Python built-ins and the standard library already have a standard idiom for
> specifying multiple values at once. A tuple of types is the One Obvious Way
> to do this:
>
> @fun.register((float, Decimal))

It's not obvious, it's ambiguous - some third party libraries use that
notation for multi-method dispatch, and they always will, no matter
what notation we choose for the standard library.

We have three available notations to register the same function for
multiple types: stacked decorators, tuple-of-types and multiple
arguments.

Of those, the first we *cannot avoid* supporting, since we want to
return the undecorated function regardless for pickle support and ease
of testing.

The second two are both used as notations by existing third party
multiple dispatch libraries.

Thus, your request is that we add a second way to do it that is
*known* to conflict with existing third party practices. There is no
practical gain on offer, it merely aligns with your current sense of
aesthetics slightly better than stacked decorators do. While you're
entitled to that aesthetic preference, it isn't a valid justification
for adding an unneeded alternate spelling.

Furthermore, the proposed registration syntax in the PEP is identical
to the syntax which already exists for ABC registration as a class
decorator (http://docs.python.org/3/library/abc#abc.ABCMeta.register).

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list