Mixin class error
Kent Johnson
kent at kentsjohnson.com
Mon Mar 6 20:08:31 EST 2006
Ed Leafe wrote:
> In Dabo, we create cursor classes that combine the backend-specific
> dbapi cursor class with our own mixin class that adds framework-
> specific behaviors. This has been working well for a couple of years
> now with many different backends, but today I'm getting errors with our
> Firebird class. I've checked the kinterbasdb site, and found nothing
> there that was helpful. The error reads:
>
> TypeError: Error when calling the metaclass bases
> type 'kinterbasdb.Cursor' is not an acceptable base type
>
> Here's some simple code that will generate the error:
>
> import kinterbasdb
> KCursor = kinterbasdb.Cursor
>
> class TestMixin(object): pass
> # This next line will raise the error.
> class CombinedCursor(TestMixin, KCursor): pass
> myCursor = CombinedCursor()
>
> I'm not sure exactly what this error message means, so I don't know
> how to go about fixing it.
I have no clue but googling 'type is not an acceptable base type' finds
this thread
http://groups.google.com/group/comp.lang.python/browse_thread/thread/628b8ad34a36db17/579f716b143f4967%23579f716b143f4967?sa=X&oi=groupsr&start=0&num=3
which points to the Py_TPFLAGS_BASETYPE. This example
http://www.python.org/doc/2.3.5/ext/node22.html
shows that flag being set to indicate that an extension class may be
subclassed; the API docs confirm this:
http://docs.python.org/api/type-structs.html#l2h-968
So it looks like kinterbasdb.Cursor is a C extension class that may not
be subclassed because Py_TPFLAGS_BASETYPE is not set. Whether this is by
design or accident would be a question for the kinterbasdb developers.
One workaround might be to use delegation instead of subclassing...
Kent
More information about the Python-list
mailing list