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
>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.
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):
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
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
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
>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
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):
>
>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
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
10 matches
Mail list logo