[Python-Dev] Classes and Metaclasses in Smalltalk
Thomas Heller
thomas.heller@ion-tof.com
Wed, 2 May 2001 16:53:17 +0200
This implementation of super works correctly:
import new
class super:
def __init__(self, instance, klass):
self.instance = instance
self.klass = klass
def __getattr__(self, name):
for klass in (self.klass,) + self.klass.__bases__:
member = getattr(klass, name, None)
if member:
if callable(member):
return new.instancemethod(member, self.instance, klass)
return member
raise AttributeError(name)
class X:
def test(self):
print "test X"
class Y(X):
def test(self):
print "test Y"
super(self, X).test()
class Z(Y):
pass
X().test()
print
Y().test()
print
Z().test()
print
Thomas