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?


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.

Python-Dev mailing list

Reply via email to