<div dir="ltr">Hi,<div><br></div><div>Does anyone know how to use __metaclass__ specification alongside inheritance from boost python classes? This code illustrates the problem:</div><div><br></div><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
import abc<br>from scitbx.lstbx import normal_eqns<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">class Refinery(object):<br> __metaclass__ = abc.ABCMeta<br>
pass<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
class AdaptLstbx(Refinery, normal_eqns.non_linear_ls):<br> pass</blockquote></div><div><br></div><div>The result is</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br> File "/usr/lib/python2.7/abc.py", line 87, in __new__<br> cls = super(ABCMeta, mcls).__new__(mcls, name, bases, namespace)<br>
TypeError: Error when calling the metaclass bases<br> metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases</blockquote></div><div><br></div><div>The real Refinery is a class that has one method that must be supplied by a concrete subclass. I like the idea of making it impossible to instantiate a base Refinery rather than relying on e.g. raise NotImplementedError() in that method definition. This is what ABCMeta would give me, if only I could get it to work here. Google found me some answers that require me to know the __metaclass__ of the bases (as suggested by the error message), but normal_eqns.non_linear_ls.__metaclass__ does not exist.</div>
<div><br></div><div>I don't terribly mind the raise NotImplementedError() alternative, but I thought that if I can easily use ABCMeta, I'd like to.</div><div><br></div><div>Cheers</div><div><br></div><div>-- David<br>
</div>
</div></div>