Abstract class + mixin + multiple inheritance in python -


Therefore, I think the code probably indicates that as I can improve in words, here goes: < / P>

  import ABC square foo (object): __metaclass__ = abc.ABCMeta @ abc.abstractmethod def bar (self): pass class bar_for_foo_mixin (object): def bar (self): print "must summarize it Meet the requirement of method requirements "class myfoo (foo, bar_for_foo_mixin): def __init __ (self): The print is called" myfoo __init__ ". Self.bar () obj = myfoo ()  

Result:

  typeError: abstract methods can not instantiate myfoo of class with the bar < / Code> 

I am trying to get the mixing class to meet the requirements of the abstract / interface class what am I missing?

Should not the legacy be on the other side? MRO foo currently comes before bar_for_foo_mixin , and then complains correctly. This should work with class myfoo (bar_for_foo_mixin, foo) .

And I'm not sure if your classroom design is the right way to do this. Since you use a mixer to apply the bar , it can not be better to get it from Foo and it is called 'foo' class (i.e. foo.register ( Myfoo) ). .

For perfection, here it is.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -