classmethod() not inherited?

Jack Diederich jack at performancedrivers.com
Thu Jan 16 10:43:35 CET 2003


How is it possible to have classmethods still be
classmethods in their kids?

-- file Test.py --
class Base(object):
  def foo(cls):
    return 'BASE!'
  foo = classmethod(foo)

class A(Base):
  def foo(cls):
    return 'some value'

class B(Base):
  def foo(cls):
    return 'some other value'

class Z(Base):
  def foo(cls):
    return 'something else still'

I'd like to have ALL of the derivitives of Base
have foo as a classmethod, but it doesn't seem
to be automatic and the following doesn't work

import Test

for (Test.A .. Test.Z): # pseudo code
  Test.A.foo = classmethod(Test.A.foo)

The Base class might have several classmethods
so adding all of them to each of the derivitives
is an error prone cut-n-paste nightmare.

google groups turns up lots of convos about type()
and new style classes, but I couldn't find anything
for this in particular.  [I'm Running Python 2.2.1]

hating cut-n-paste-ly yours,

-jackdied





More information about the Python-list mailing list