On Feb 25, 11:04 am, [EMAIL PROTECTED] wrote: > > B1.fun(A(x), A(y), A(z)) == B.fun(A(x), A(y), A(z)) > > but > > B1.fun(A1(x), A(y), A(z) != B.fun(A1(x), A(y), A(z)) > > > Is there a data-structure solution or third party module that would > > mimic this behavior? > > class B: > xfun= Overloaded() > def fun( self, *a ): > return self.xfun.dispatch( self, *a ) > [EMAIL PROTECTED]( A, A, A ) > def q( self, x, y, z ): > return 'B AAA' > [EMAIL PROTECTED]( A1, A, A ) > def q( self, x, y, z ): > return 'B A1AA' > B.xfun.push( B )
You could also call xfun.methods( self ) in B.__init__. Overloaded.methods binds the methods specified with xfun.make to the B instance. In this case, the effect is, self.fun= types.MethodType( self.__class__.[x?]fun, self ) -- I forget by now. But time is money, and money doesn't grow on trees-- so catch me later with your own. (A decorator could also do it too-- and just in the base class!) -- http://mail.python.org/mailman/listinfo/python-list