[Python-ideas] Wild idea about mutability

Rob Cliffe rob.cliffe at btinternet.com
Tue Jun 7 09:24:22 EDT 2016



On 06/06/2016 11:44, Sven R. Kunze wrote:
>
>
> Thinking this further, __init__ would be the only function to change 
> the state of an immutable object. Once created, it will never change. 
> Immutable also implies hashability IMHO. Moreover, immutable object 
> would not be allowed to query data from global/external variables as 
> those can change and would change the observable state of the object 
> without the object noticing. So, the allowed way of creating a state 
> for an immutable object would be using a new container as you did (by 
> defining self._cache) and store immutable objects only there. Would 
> this make sense?
>
> Sven
That would be one viable design.
But aren't there use cases for initially creating an object as mutable, 
then at some point "freezing" it by changing the mutable flag from True 
to False?
(Obviously the converse would not be allowed.)
Regards,
Rob Cliffe


More information about the Python-ideas mailing list