[Python-ideas] Wild idea about mutability
Sven R. Kunze
srkunze at mail.de
Wed Jun 8 09:53:50 EDT 2016
On 07.06.2016 15:24, Rob Cliffe wrote:
>
>
> 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.)
Object freezing sounds like a crazy dynamic idea.
Unfreezing would be even crazier.
I think that would be even better than a static mutable flag. I like
that. :)
Sven
More information about the Python-ideas
mailing list