diff --git a/src/__init__.py b/src/__init__.py index 04a3fa7cfaf7ba4d7524df853dd827798bd711b2..9f55d8d4acfa3dbe948bdbf33a4e5e2739e11774 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -347,6 +347,7 @@ class InfixOperator: def monkeypatch_method(cls): + # from GvR, http://mail.python.org/pipermail/python-dev/2008-January/076194.html def decorator(func): setattr(cls, func.__name__, func) return func @@ -355,6 +356,19 @@ def monkeypatch_method(cls): +def monkeypatch_class(name, bases, namespace): + # from GvR, http://mail.python.org/pipermail/python-dev/2008-January/076194.html + + assert len(bases) == 1, "Exactly one base class required" + base = bases[0] + for name, value in namespace.iteritems(): + if name != "__metaclass__": + setattr(base, name, value) + return base + + + + # Generic utilities ---------------------------------------------------------- def flatten(list): """For an iterable of sub-iterables, generate each member of each