468,766 Members | 1,292 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,766 developers. It's quick & easy.

Mixin class error

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

Mar 6 '06 #1
3 1286
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....&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
Mar 7 '06 #2
On Mar 6, 2006, at 8:08 PM, Kent Johnson wrote:
I have no clue but googling 'type is not an acceptable base type'
finds
this thread
http://groups.google.com/group/comp....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

Mar 7 '06 #3
Ed Leafe wrote:
On Mar 6, 2006, at 8:08 PM, Kent Johnson wrote:
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.


Automatic delegation is pretty simple, just define __getattr__() and
__setattr__() to delegate to the wrapped class. For example
http://aspn.activestate.com/ASPN/Coo...n/Recipe/52295

Kent
Mar 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by zimba | last post: by
5 posts views Thread by Udo Gleich | last post: by
reply views Thread by Paolino | last post: by
reply views Thread by barnesc | last post: by
6 posts views Thread by Alex Hunsley | last post: by
2 posts views Thread by ish | last post: by
1 post views Thread by Ole Nielsby | last post: by
2 posts views Thread by viboes | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.