It looks like work for ... a metaclass!
def make_method(p, m): def method(self, *a, **k): return getattr(getattr(self, p),m)(*a, **k) return method class Proxier(type): def __new__(cls, name, bases, dict): objs = dict.get('proxyobjs', []) if objs: old_init = dict.get('__init__', lambda self: None) def new_init(self, *a, **k): for (n,v) in objs.iteritems(): setattr(self, n, v()) old_init(self, *a, **k) dict['__init__'] = new_init meths = dict.get('proxymethods', {}) for (proxyname, methnames) in meths.iteritems(): for methname in methnames: dict[methname] = make_method(proxyname, methname) return super(Proxier, cls).__new__(cls, name, bases, dict) class Spam(object): __metaclass__ = Proxier proxyobjs = {'ham': dict, 'eggs': list, } proxymethods = {'ham': ('__setitem__', '__getitem__', '__delitem__'), 'eggs': ('__contains__', 'append') }
It works!
In [28]: s = Spam() In [29]: s[4] = 'hi' In [30]: s.append(3) In [31]: 3 in s Out[31]: True In [32]: 4 in s Out[32]: False In [33]: s[4] Out[33]: 'hi'
Note that you must indicate which parts of the interface you are using (otherwise, why not just inherit?). So we have __contains__ from list and __getitem__ from dict , and __iter__ from none. (And there is only one way to change the base list using append , but not extend or __delitem__ .) So (like Martian), I'm not sure how useful this is.