Pipe in the "return" statement

Archard Lias archardlias at googlemail.com
Mon Jul 25 18:30:27 CEST 2011


On 25 Jul., 18:11, Christian Heimes <li... at cheimes.de> wrote:
> Am 25.07.2011 17:28, schrieb Archard Lias:
>
> > It would be great if you could elaborate a little more on that. Am I
> > not supposed to access the parent here?
>
> You must spell out the parent explicitly, otherwise subclasses call
> super() with themselves rather than the correct parent class.
> self.__class__ is too dynamic here. Have a look at this example:
>
> class A(object):
>     def method(self):
>         pass
>
> class B(A):
>     def method(self):
>         super(self.__class__, self).method()
>
> class C(B):
>     pass
>
> In this example, C().method() results in "super(C, self).method()"
> because self.__class__ is C. However that is wrong because you have to
> call super() with the direct parent.
>
> Christian

Oh! Get it, thanks a lot :P

--
Archard



More information about the Python-list mailing list