I'd like to be able to do:
>>> class a(str):
... pass
...
>>> b = a()
>>> b.__class__ = str
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __class__ assignment: only for heap types
I'd like to be able to do:
>>> class a(str):
... pass
...
>>> b = a()
>>> b.__class__ = str
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __class__ assignment: only for heap types
Only classes that were defined with a class
keyword could be used for __class__
attribute assignment:
>>> class C:
pass
>>> class D:
pass
>>> C().__class__ = D
>>>
I've solved it in this way:
>>> class C(str):
... def __getattribute__(self, name):
... if name == '__class__':
... return str
... else:
... return super(C, self).__getattribute(name)
...
>>> c = C()
>>> c.__class__
<type 'str'>