[Python-ideas] Wild idea about mutability

Eric V. Smith eric at trueblade.com
Wed Jun 8 10:33:29 EDT 2016


> On Jun 8, 2016, at 9:53 AM, Sven R. Kunze <srkunze at mail.de> wrote:
> 
>> 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. :)
> 

See the rejected PEP-351 for one version of the freeze protocol. 

--
Eric.




More information about the Python-ideas mailing list