extending class

Andrea Crotti andrea.crotti.0 at gmail.com
Fri Sep 23 11:12:10 CEST 2011

I wanted to add a couple of parameters to a class from a given library 
(paste-script), but without changing the original code.
So I thought, I create a wrapper class which adds what I need, and then 
dispatch all the calls to the super class.

My following attempt gives, however, a recursion error, but why?

class PSIVar(object):
     """Extend var implementation from the paste-script, to add the
     ability of correlating variables
 >>> v = var("name", "desc")
 >>> v.name == 'name'
 >>> v1 = PSIVar(v)
 >>> v1.name == 'name'
     def __init__(self, first_var, other=None, fun=None):
         # this is of type defined there
         self.first_var = first_var
         if other is not None:
             self.other = other
             self.fun = fun
             assert callable(self.fun)

     # now try to dispatch every method call to the other class
     # must probably call the super class
     def __getattribute__(self, attr):
         return self.first_var.__getattribute__(attr)

More information about the Python-list mailing list