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

Nicko van Someren nicko at nicko.org
Sat Jan 19 18:19:43 CET 2008


On 15 Jan 2008, at 15:37, Guido van Rossum wrote:
> Second, a "metaclass" to add a number of methods (or other attributes)
> to an existing class, using a convenient class notation:
...
> class <newclass>(<someclass>):
>    __metaclass__ = monkeypatch_class
>    def <method1>(...): ...
>    def <method2>(...): ...
>    ...

In Objective-C it's perfectly common to extend existing classes using  
'categories' and I have often found this idiom very useful.  What is  
described here is basically categories for Python.  I've implemented  
something like this before and I would be happy to see this added to  
the standard library and formalised.

	Nicko



More information about the Python-Dev mailing list