"Phillip J. Eby" <pje@telecommunity.com> writes: > The problem here is that B.__metaclass__ *must* be the same as, or a > subclass of, A.__metaclass__, or vice versa. It doesn't matter > whether the metaclass is specified implicitly or explicitly, this > constraint must be met. Your code doesn't meet this constraint. > Here's a revised example that does: > > class A(object): > class __metaclass__(type): > pass > > class B(A): > class __metaclass__(A.__class__): > pass > > B.__metaclass__ will now meet the "metaclass inheritance" constraint. > See the "descrintro" document for some more info about this, and the > "Putting Metaclasses To Work" book for even more info about it than > you would ever want to know. :) I knew all that once, and have since forgotten more than I knew :(. I actually already managed to make the code work by doing what you did above, so it couldn't have been buried too deeply in the caves of my brain. > Here's a short statement of the constraint, though: > > A class X's metaclass (X.__class__) must be identical to, or a > subclass of, the metaclass of *every* class in X.__bases__. That is: > > for b in X.__bases__: > assert X.__class__ is b.__class__ or issubclass(X.__class, b.__class__),\ > "metatype conflict among bases" Still, the message is misleading. There's only one base class, so the metatype conflict is not "among bases". -- Dave Abrahams Boost Consulting www.boost-consulting.com
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4