A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-May/014539.html below:

[Python-Dev] Classes and Metaclasses in Smalltalk

[Python-Dev] Classes and Metaclasses in SmalltalkThomas 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




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4