deriving classes from object extensions

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

    #1

    deriving classes from object extensions

    Hi,

    I am using Python with Cache dbase, which provides pythonbind module,
    and intersys.python bind.object types. But I can't create a class based
    on this type:

    import intersys.python bind
    class MyClass(intersy s.pythonbind.ob ject):
    pass

    gives me the error: TypeError: Error when calling the metaclass bases
    type 'intersys.pytho nbind.object' is not an acceptable base type

    Can anyone expain if it is possible for me to derive my own class from
    the intersys object so as to add my own functionality?

    thanks,
    matthew

  • Calvin Spealman

    #2
    Re: deriving classes from object extensions

    On 7 Dec 2006 16:12:18 -0800, manstey <manstey@csu.ed u.auwrote:
    Hi,
    >
    I am using Python with Cache dbase, which provides pythonbind module,
    and intersys.python bind.object types. But I can't create a class based
    on this type:
    >
    import intersys.python bind
    class MyClass(intersy s.pythonbind.ob ject):
    pass
    >
    gives me the error: TypeError: Error when calling the metaclass bases
    type 'intersys.pytho nbind.object' is not an acceptable base type
    >
    Can anyone expain if it is possible for me to derive my own class from
    the intersys object so as to add my own functionality?
    >
    thanks,
    matthew
    >
    --

    >
    Sounds like they are following outdated APIs before the new-style
    classes. The builtin types have been updated to be compatible with the
    newstyle classes, but your example is of an extension type that does
    not have such treatment. It simply is not inheritable, because it is
    from the era where one could not derive from any builtin types.

    The only solution you really have to use delegation instead of
    inheritence. Create your class by itself, give it a reference to an
    instance of intersys.python bind.object, and have it look for expected
    attributes there. To be a little nicer, you could have a special
    __getattr__ method to look up unfound attributes on the delegation
    object, your intersys.python bind.object instance.

    class Delegating(obje ct):
    def __init__(self, old_object):
    self._old_objec t = old_object
    def __getattr__(sel f, name):
    return getattr(self._o ld_object, name)

    d = Delegating(my_o ld_object)
    d.my_old_attrib ute

    --
    Read my blog! I depend on your acceptance of my opinion! I am interesting!

    Comment

    Working...