By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,088 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,088 IT Pros & Developers. It's quick & easy.

deriving classes from object extensions

P: n/a
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

Dec 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 7 Dec 2006 16:12:18 -0800, manstey <ma*****@csu.edu.auwrote:
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

--
http://mail.python.org/mailman/listinfo/python-list
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

--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
Dec 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.