Mixin class error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ed Leafe

    #1

    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.Cu rsor' is not an acceptable base type

    Here's some simple code that will generate the error:

    import kinterbasdb
    KCursor = kinterbasdb.Cur sor

    class TestMixin(objec t): 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



  • Kent Johnson

    #2
    Re: Mixin class error

    Ed Leafe wrote:[color=blue]
    > 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.Cu rsor' is not an acceptable base type
    >
    > Here's some simple code that will generate the error:
    >
    > import kinterbasdb
    > KCursor = kinterbasdb.Cur sor
    >
    > class TestMixin(objec t): 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.[/color]

    I have no clue but googling 'type is not an acceptable base type' finds
    this thread


    which points to the Py_TPFLAGS_BASE TYPE. This example
    The official home of the Python Programming Language


    shows that flag being set to indicate that an extension class may be
    subclassed; the API docs confirm this:


    So it looks like kinterbasdb.Cur sor is a C extension class that may not
    be subclassed because Py_TPFLAGS_BASE TYPE 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

    Comment

    • Ed Leafe

      #3
      Re: Mixin class error

      On Mar 6, 2006, at 8:08 PM, Kent Johnson wrote:
      [color=blue]
      > 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/628b8ad34a36db1 7/579f716b143f496 7%23579f716b143 f4967?
      > sa=X&oi=groupsr &start=0&num =3[/color]

      I spent about an hour Googling and never found that thread!
      [color=blue]
      > So it looks like kinterbasdb.Cur sor is a C extension class that may
      > not
      > be subclassed because Py_TPFLAGS_BASE TYPE is not set. Whether this
      > is by
      > design or accident would be a question for the kinterbasdb developers.[/color]

      OK, I'll ask them.
      [color=blue]
      > One workaround might be to use delegation instead of subclassing...[/color]

      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



      Comment

      • Kent Johnson

        #4
        Re: Mixin class error

        Ed Leafe wrote:[color=blue]
        > On Mar 6, 2006, at 8:08 PM, Kent Johnson wrote:[color=green]
        >> One workaround might be to use delegation instead of subclassing...[/color]
        >
        > Yeah, but that would involve a lot more work at this point. The
        > mixin approach has been working quite well up until this problem.[/color]

        Automatic delegation is pretty simple, just define __getattr__() and
        __setattr__() to delegate to the wrapped class. For example


        Kent

        Comment

        Working...