On 10/29/2012 1:05 PM, andrea crotti wrote:

I meant how do I create new immutables classes myself, I guess that's
possible writing C extensions but I don't see in pure Python..

If you mean class with immutable instances, mutate new instances in __new__ instead of __init__ and write a custom .__setattr__ that prevents changes thereafter.

If you want the class itself to be immutable (after creation), write a custom metaclass.

You may also need to think about .__getattribute__, but I never studied the detail completely and have forgotten what I learned.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to