2 Create subclasses that call out to their "superclass" for all methods
3 but return the "subclass's" type
6 def wrapper(cls, func):
7 return (lambda self, *args: cls(getattr(self.value, func)(*map(self.value.__class__, args))))
9 class SmartSubclass(object):
10 def __init__(self, superclass, exclude=None):
13 self.superclass = superclass
14 self.exclude = exclude
15 def __call__(self, name, bases, dict):
16 c = type(name, bases, dict)
17 for func in dir(self.superclass):
18 if func not in dir(c) and \
19 callable(getattr(self.superclass, func)) and \
20 func not in self.exclude:
21 setattr(c, func, wrapper(c, func))
24 __all__ = ['SmartSubclass']