Created
May 13, 2011 19:29
-
-
Save markpasc/971155 to your computer and use it in GitHub Desktop.
python diamond inheritance works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base(object): | |
def data(self): | |
return {'base': True} | |
class A(Base): | |
def data(self): | |
data = super(A, self).data() | |
data.update({'a': True}) | |
return data | |
class B(Base): | |
def data(self): | |
data = super(B, self).data() | |
data.update({'b': True}) | |
return data | |
class C(A, B): | |
def data(self): | |
data = super(C, self).data() | |
data.update({'c': True}) | |
return data | |
print repr(C().data()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python diamond.py | |
{'a': True, 'c': True, 'base': True, 'b': True} | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment