Down casting Python objects

Andrey Fedorov anfedorov at
Tue Mar 9 22:26:52 CET 2010

So I have `x', a instance of class `Foo'. I also have class `Bar', a class
extending `Foo' with a couple of methods. I'd like to "down cast" x as
efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect
things to work OK in all major versions of CPython?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list