[cctbxbb] boost python and metaclass inheritance
David Waterman
dgwaterman at gmail.com
Fri Jan 10 06:37:19 PST 2014
Hi Luc,
Actually it almost works, because Refinery should not inherit
from normal_eqns.non_linear_ls, only the adapter, AdaptLstbx. So I can do:
import abc
from scitbx.lstbx import normal_eqns
class Refinery(object):
__metaclass__ = abc.ABCMeta
pass
class AdaptLstbx(Refinery, normal_eqns.non_linear_ls):
class __metaclass__(normal_eqns.non_linear_ls.__class__, abc.ABCMeta):
pass
pass
This successfully stops Refinery being constructed. However, you do point
out the critical flaw, which is that AdaptLstbx can now be constructed, yet
this still lacks the missing 'run' method, which would be supplied another
child. Now the original raise NotImplementedError() seems like the clearest
solution. I suppose this is why people on the internet argue that abc isn't
pythonic.
Cheers
-- David
On 9 January 2014 00:48, Luc Bourhis <luc_j_bourhis at mac.com> wrote:
> > import abc
> > from scitbx.lstbx import normal_eqns
> > class Refinery(object):
> > class __metaclass__(normal_eqns.non_linear_ls.__class__, abc.ABCMeta):
> pass
> >
> > class AdaptLstbx(Refinery, normal_eqns.non_linear_ls): pass
>
> Except that it does not prevent
> r = Refinery()
> after all since the __metaclass__ has a valid instantiation through
> normal_eqns.non_linear_ls.__class__.
>
> which gives me a flashback: I've already burnt myself with that!
>
> Luc
>
> _______________________________________________
> cctbxbb mailing list
> cctbxbb at phenix-online.org
> http://phenix-online.org/mailman/listinfo/cctbxbb
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://phenix-online.org/pipermail/cctbxbb/attachments/20140110/1c344835/attachment.htm>
More information about the cctbxbb
mailing list