Python2.1/ExtensionClass: Changing the __class__

Sebastien Bigaret Sebastien.Bigaret at inqual.com
Tue Aug 27 21:04:51 CEST 2002


        Hi,

  This is for python2.1

  Is it possible to dynamically cast an instance of 'class A(ExtensionClass)'
to 'class B(A)'? (In my case, 'ExtensionClass' can be either ZODB.Persistent
or Zope's Acquisition.Implicit)

  Something like:  a.__class__=B (if only it worked!)

Having made some researches, it seems to me that this is not possible, but I
couldn't find any document stating it clearly.

I'd like to find a way to either change such an instance's class, or its base
classes, or a way to weakref it (ExtensionClass instances seem not to be
weakly referencable). My use-case is that the object should be casted to
another class without changing its reference. Can anyone think of a solution?

  Or is it simply not possible with python2.1 and ExtensionClass? In that
case, is it possible to write a proxy object that really proxies __dict__,
__class__, etc., while allowing the proxied extension-class object to be
changed?

 Cheers,

-- Sebastien.







More information about the Python-list mailing list