[Python-Dev] Metatype conflict among bases? (original) (raw)
David Abrahams dave@boost-consulting.com
Tue, 22 Apr 2003 22:39:11 -0400
- Previous message: [Python-Dev] Metatype conflict among bases?
- Next message: [Python-Dev] Metatype conflict among bases?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"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
- Previous message: [Python-Dev] Metatype conflict among bases?
- Next message: [Python-Dev] Metatype conflict among bases?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]