Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# -*- coding: euc-jp -*-"
class Base1:
pass
class Base2:
def method(self):
print('Base2')
class MyClass(Base1, Base2):
pass
here = MyClass()
here.method() # Base2
class BaseBase:
def method(self):
print('BaseBase')
class Base1(BaseBase):
pass
class Base2(BaseBase):
def method(self):
print('Base2')
class MyClass(Base1, Base2):
pass
# 古いMROは左から右への深さ優先というルールに従って動作するため、
# Base2を探す前に、最初のBase1クラスの親を探索できるところまで
# 探索しようとする。故に下のようなコードを書くとBaseBaseまでいきつく
here = MyClass()
here.method() # BaseBase
class BaseBase(object):
def method(self):
print('BaseBase')
class Base1(BaseBase):
pass
class Base2(BaseBase):
def method(self):
print('Base2')
class MyClass(Base1, Base2):
pass
here = MyClass()
here.method()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.