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

Nick Coghlan ncoghlan at gmail.com
Fri May 24 14:37:26 CEST 2013


On Fri, May 24, 2013 at 10:22 PM, Ronan Lamy <ronan.lamy at gmail.com> wrote:
> Raise a ValueError, maybe? In that case, there needs to be a way to force
> the overriding when it is explicitly desired. One way would be to allow
> unregistering implementations: overriding is then done by unregistering the
> old implementation before defining the new one. This is a bit cumbersome,
> which IMHO is a good thing for an operation that is just as disruptive as
> monkey-patching a class or a module.

If you're registering an implementation for a type you didn't define
on a generic function you didn't define, it's *exactly* as disruptive
as monkey-patching. Note that the PEP proposes giving exactly as much
of a runtime warning about overwriting a registration as we do about
monkeypatching: none.

The two cases are exactly analagous: you can do it, you don't get a
warning if you do it, but it you do it implicitly as a side effect of
import then you will have developers cursing your name. So don't do
that, put it in a function that people can call if they want to
register your implementations (along the lines of gevent.monkey).

Cheers,
Nick.

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


More information about the Python-Dev mailing list