[Python-Dev] Monkeypatching idioms -- elegant or ugly?

Phillip J. Eby pje at telecommunity.com
Tue Jan 15 23:08:37 CET 2008


At 01:51 PM 1/15/2008 -0800, Guido van Rossum wrote:
>On Jan 15, 2008 1:27 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> > > Second, a "metaclass" to add a number of methods (or other attributes)
> > > to an existing class, using a convenient class notation:
> >
> > I think this is similar to my "partial" classes:
> >
> > http://pypi.python.org/pypi/partial
>
>Indeed it is. I guess my only innovation is realizing that you don't
>have to create a real metaclass -- you can set __metaclass__ to a
>function that does the magic. I like your feature of refusing
>overrides unless flagged with @replace.
>
>I think that despite the objection that monkeypatching shoudn't be
>made too easy, it's worth at looking into a unification of the API,
>features, and implementation.

I'm curious: has this affected your thoughts re: overloading existing 
functions? Note that overloading-in-place would provide the 
next_method idiom for calling the original function.

(I'm assuming you still don't like the idea of changing a function's 
code to do it, just wondering about the non-implementation aspect.  :) )



More information about the Python-Dev mailing list