[Python-Dev] Dataclasses, frozen and __post_init__

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Feb 20 19:13:36 EST 2018


Steven D'Aprano wrote:
> 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.

That seems unfriendly to subclasses as well. To extend a class
you now need to subclass both the mutable and immutable versions
of the base class, ensure they share the behaviour they should
have in common (possibly by using a third mixin class) and
arrange for the freezing switch to install the immutable subclass
instead of the base one.

All of which seems like a huge amount of hassle just to save
an instance attribute. And I don't even want to think what
multiple inheritance would do to all this.

-- 
Greg


More information about the Python-Dev mailing list