Steven D'Aprano added the comment: A further thought... looking at your example code, I believe that part of the __getattr__ is redundant.
def __getattr__(self, item): try: return self.__getattribute__(item) except AttributeError: return self.f.__getattribute__(item) __getattr__ is only called if normal attribute lookup has already failed, so the call to self.__getattribute__ is unnecessary. If it would have succeeded, it would have already succeeded and __getattr__ won't have been called at all. For more discussion on how to do automatic delegation, you should look at Alex Martelli's recipe from the Python Cookbook: https://code.activestate.com/recipes/52295-automatic-delegation-as-an-alternative-to-inherita/ Also, its a bit... funny... to call dunder methods directly. (I'm deliberately not using the word "wrong".) They are implementation, not interface. I think your __getattr__ should be: def __getattr__(self, name): return getattr(self.f, name) It also looks nicer :-) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30352> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com