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

Antoine Pitrou solipsis at pitrou.net
Tue Jan 15 17:22:25 CET 2008


Guido van Rossum <guido <at> python.org> writes:
> 
> I ran into the need of monkeypatching a large number of classes (for
> what I think are very good reasons  and invented two new recipes.
> These don't depend on Py3k, and the second one actually works all the
> way back to Python 2.2. Neither of these allows monkeypatching
> built-in types like list. If you don't know what monkeypatching is,
> see see http://en.wikipedia.org/wiki/Monkey_patch.
> 
> I think it's useful to share these recipes, if only to to establish
> whether they have been discovered before, or to decide whether they
> are worthy of a place in the standard library. I didn't find any
> relevant hits on the ASPN Python cookbook.

pypy has something that requires the base class to use a specific metaclass:
https://codespeak.net/viewvc/pypy/dist/pypy/tool/pairtype.py?view=markup





More information about the Python-Dev mailing list