On Wed, 27 Apr 2016 02:26 am, Random832 wrote: > On Tue, Apr 26, 2016, at 12:12, Steven D'Aprano wrote: >> The obvious reason for overriding __new__ is to construct an immutable >> instance. You have to override __new__, because by the time it returns >> the >> instance is immutable and you can no longer initialise it. > > Other than by subclassing an existing immutable type written in C, is it > actually possible to define a truly-immutable (rather than > contract-immutable) class in python?
No. Subclassing immutable built-ins is the most obvious and simple (and probably common) way to get an immutable class. Actually immutable, short of doing wicked things with ctypes. > (Of course, subclassing immutable C types is the more obvious answer to > when you have to override __new__). Indeed. -- Steven -- https://mail.python.org/mailman/listinfo/python-list