On Mon, Feb 19, 2018 at 07:02:42PM -0800, Guido van Rossum wrote:

> On Mon, Feb 19, 2018 at 5:06 PM, Chris Barker - NOAA Federal <
> chris.bar...@noaa.gov> wrote:
[...]
> > This seems another use case — maybe it would be helpful to be able to
> > freeze an instance after creation for multiple use-cases?
>
> But how?

I haven't got all the details yet, but how badly do you hate the
technique of swapping out __class__ to get a change in behaviour?

https://www.safaribooksonline.com/library/view/python-cookbook/0596001673/ch05s19.html

or https://code.activestate.com/recipes/68429-ring-buffer/

(I believe that in the Objective C community, something very close to 
this is called "swizzling".)

So in principle, we could have a mutable class, and a immutable one, and 
when you flick the switch, the instance.__class__ changes from mutable 
to frozen.

If you don't hate this, we can think about the details needed to get 
it work in practice.



-- 
Steve
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to