Giovanni Bajo wrote:
> Hello,
>
> what's the magic needed to reuse the base-class implementation of a
> classmethod?
>
> class A(object):
> @classmethod
> def foo(cls, a,b):
> # do something
> pass
>
> class B(A):
> @classmethod
> def foo(cls, a, b):
> A.foo(cls, a, b) # WRONG!
>
> I need to call the base-class classmethod to reuse its implementation, but I'd
> like to pass the derived class as first argument.
> --
> Giovanni Bajo
See the super object. In your case, it can be used like this:
class B(A):
@classmethod
def foo(cls, a, b):
super(B, cls).foo(a, b)
This all assumes you want to modify the behavior of foo in a subclass.
If not, of course, you don't need to override it at all.
-- David
--
http://mail.python.org/mailman/listinfo/python-list