Re: [Python-Dev] Dataclasses, frozen and __post_init__

2018年2月19日 21:14:51 -0800

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 <
> [email protected]> 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
[email protected]
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