他のクラスが継承する基本クラスがあります。
class AppToolbar(wx.ToolBar):
''' Base class for the Canary toolbars '''
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# ... a few common implementation details that work as expected...
self._PopulateToolbar()
self.Realize()
基本クラスは を実装していません (実装できません) _PopulateToolbar()
。抽象メソッドである必要があります。そのため、使用abc
するのが良い計画だと考えたので、これを試しました:
class AppToolbar(wx.ToolBar, metaclass=abc.ABCMeta):
# ... as above, but with the following added
@abc.abstractmethod
def _PopulateToolbar():
pass
当然のことながら、これを実行しようとするとTypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
. 私は「ああ、そうだ、ミックスインを使うだけだ」と思った:
class PopulateToolbarMixin(metaclass=ABCMeta):
@abstractmethod
def _PopulateToolbar(self):
pass
PopulateToolbarMixin.register(wx.ToolBar)
PopulateToolbarMixin.register(AppToolbar)
変更なし: 同じTypeError
メッセージです。ABCMeta
ここを使用すると、明らかな何かが欠けていると思います。これは wxPython 固有のエラーではないようです。私は何を間違っていますか?同じ問題にアプローチするより良い方法はありますか?
編集:同僚との会話で、メタクラスを混在させることはできないと指摘されました。wx.ToolBar
どうやら から派生しているためsip.wrappertype
、これを行う方法はないようです。ここで「抽象メソッド」アプローチを処理する別のまだ Pythonic な方法は何ですか?