Down casting Python objects

Andrey Fedorov anfedorov at gmail.com
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: <http://mail.python.org/pipermail/python-list/attachments/20100309/596fcfda/attachment.html>


More information about the Python-list mailing list