deriving classes from object extensions

M

manstey

Hi,

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

import intersys.pythonbind
class MyClass(intersys.pythonbind.object):
pass

gives me the error: TypeError: Error when calling the metaclass bases
type 'intersys.pythonbind.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
 
C

Calvin Spealman

Hi,

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

import intersys.pythonbind
class MyClass(intersys.pythonbind.object):
pass

gives me the error: TypeError: Error when calling the metaclass bases
type 'intersys.pythonbind.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.pythonbind.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.pythonbind.object instance.

class Delegating(object):
def __init__(self, old_object):
self._old_object = old_object
def __getattr__(self, name):
return getattr(self._old_object, name)

d = Delegating(my_old_object)
d.my_old_attribute
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top