Mixin class error

E

Ed Leafe

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. Here's my setup:

Windows 2000
Python v. 2.4.1
kinterbasdb 3.2.0a1

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
 
K

Kent Johnson

Ed said:
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...79f716b143f4967?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
 
E

Ed Leafe

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

I spent about an hour Googling and never found that thread!
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.

OK, I'll ask them.
One workaround might be to use delegation instead of subclassing...

Yeah, but that would involve a lot more work at this point. The
mixin approach has been working quite well up until this problem.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top