[Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

Jim Jewett jimjjewett at gmail.com
Mon Apr 3 16:12:09 CEST 2006


On 4/1/06, Alex Martelli <aleaxit at gmail.com> wrote:

> [Monkeypatching]  may just be impossible for ``classes'' that
> are actually types implemented in C, as is the case for gmpy.

> ... Rather, look (e.g.) at copy_reg for the typical kludge
> that's used to reimplement that crucial design pattern
> that is adaptation, over and over and over again.

Right -- as an implementation issue, monkeypatching an extension class
is ugly, and requires cooperation from the caller.

As I see it, there are three possibilities for adaptation:

(1)  The callee helps explicitly.  (In which case, why not just do it directly?)

(2)  The caller helps explicitly.  This is the equivalent of the
copy_reg hack.  (Except that there might be single registry for all
adaptations, instead of separate ones for each piece of functionality.
 Is that really the key advantage you're looking for?)

(3)  Neither the callee nor the caller has to change; if there are
problems, the system knows to check a system registry for 3rd-party
adaptors.  This is the (less efficient) equivalent of opening all
classes to monkeypatching.  (As you mention, this is what Ruby does,
but would be a big change for python.)

-jJ


More information about the Python-3000 mailing list