Re: super() and automatic method combination

2005-05-18 Thread Steven Bethard
Laszlo Zsolt Nagy wrote: > I tested this and I realized that if you change the parameter list in > the descendants then it is not wise to use super. > I'm going to publish the example below, I hope others can learn from it > too. > [snip and fixed formatting] > > Example (bad): > > class A(obj

Re: super() and automatic method combination

2005-05-18 Thread Laszlo Zsolt Nagy
>Which is fine so long as nobody else tries to add further subclasses later: > >class C(B): ... >class Mine(AB,C): ... > >Mine().f() > >Using super throughout this works (it calls f in Mine, AB, A, C, B, and >then Base), but your explicit call to the base classes means that if you >don't call C.

Re: super() and automatic method combination

2005-05-18 Thread Steven Bethard
Paul Rubin wrote: > I'm trying the super() function as described in Python Cookbook, 1st ed, > p. 172 (Recipe 5.4). > > class A(object): > def f(self): > print 'A' > > > class B(object): > def f(self): > print 'b' > > > class C(A,B):

Re: super() and automatic method combination

2005-05-18 Thread Scott David Daniels
Laszlo Zsolt Nagy wrote: > >> The trick is that C.f only calls A.f, but A.f needs to end up calling >> B.f when it is used in a C. >> >> > I believe your response only applies to single inheritance. For classes > with muliple bases classes, you need to call the base methods one by one. > > BT

Re: super() and automatic method combination

2005-05-18 Thread Duncan Booth
Laszlo Zsolt Nagy wrote: > >>The trick is that C.f only calls A.f, but A.f needs to end up calling >>B.f when it is used in a C. >> >> > I believe your response only applies to single inheritance. For > classes with muliple bases classes, you need to call the base methods > one by one. super

Re: super() and automatic method combination

2005-05-18 Thread Michele Simionato
Paul Rubin: > It would be nice to make some decorators to do CLOS-like > automatic method combination ... You can't do that with decorators (I mean the automatic call of the supermethod) but you can with a metaclass. There is an example in my ACCU lectures: http://www.reportlab.org/~andy/accu2005

Re: super() and automatic method combination

2005-05-18 Thread Laszlo Zsolt Nagy
>The trick is that C.f only calls A.f, but A.f needs to end up calling B.f >when it is used in a C. > > I believe your response only applies to single inheritance. For classes with muliple bases classes, you need to call the base methods one by one. BTW I prefer to call the base methods in th

Re: super() and automatic method combination

2005-05-18 Thread Duncan Booth
Paul Rubin wrote: > I'm trying the super() function as described in Python Cookbook, 1st > ed, p. 172 (Recipe 5.4). > > class A(object): > def f(self): > print 'A' > > > class B(object): > def f(self): > print 'b' > > > class C(A,B):

Re: super() and automatic method combination

2005-05-18 Thread Laszlo Zsolt Nagy
> >I have the impression that this is supposed to call the f method >in both A and B, so it should print > > Not really true. The first parameter of 'super' should be a type, not an instance. > A > B > C >or maybe > B > A > C >depending on the resolution order. However, it only calls

super() and automatic method combination

2005-05-18 Thread Paul Rubin
I'm trying the super() function as described in Python Cookbook, 1st ed, p. 172 (Recipe 5.4). class A(object): def f(self): print 'A' class B(object): def f(self): print 'b' class C(A,B): def f(self): super(c,s