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

Devin Jeanpierre jeanpierreda at gmail.com
Fri May 24 12:20:55 CEST 2013


On Thu, May 23, 2013 at 6:40 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> I don't think that they will. Being able to register multiple types with a
> single call reads very naturally to me, while multiple decorators still
> looks weird. Even after many years of seeing them, I still get a momentary
> "What the hell...?" moment when I see two decorators on one function. That's
> only going to be increased when both decorators are the same (apart from the
> argument). The double decorator form above looks to me as weird as:
>
> x = func(a)
> x = func(b)
>
>
> would. I have to stop and think about what is going on, and whether or not
> it is a mistake.

That's absurd. The above is not comparable to double decorators, the
following is:

    x = func(a)
    x = func(x)

And this is clearly not something anyone has to stop and think about.
(more literally, obviously it's actually def x(...): ... ; x =
func(a)(x); x = func(b)(x))

There is nothing remotely wrong or distasteful about using multiple
decorators. It's a natural thing to want to compose multiple functions
together; for example, @functools.lru_cache with @fun.register or
@staticmethod or [...]. And it's even natural to want to apply the
same decorator with different arguments multiple times to the same
thing, if it happens to do something different when given different arguments.

-- Devin


More information about the Python-Dev mailing list