etils icon indicating copy to clipboard operation
etils copied to clipboard

Freezing unfrozen dataclasses requires unfreezing them beforehand.

Open SobhanMP opened this issue 1 year ago • 2 comments

import dataclasses
from etils import edc
@edc.dataclass(allow_unfrozen=True)
@dataclasses.dataclass(eq=True, kw_only=True)
class Conf:
    x: int = 3

a = Conf()
a.x = 2 # verify that a is not frozen
a.frozen() # complains that .frozen() can only be called after .unfrozen()

As the code above shows, allow_unfrozen seems to assume that the dataclass is frozen by default. I think that it should verify the assumption.

SobhanMP avatar Jul 19 '23 18:07 SobhanMP

Yes, this makes sense! Thank you for the feedback. Sending a fix now

Conchylicultor avatar Oct 10 '23 15:10 Conchylicultor

Would have been nice to be able to freeze not frozen data classes too.

SobhanMP avatar Oct 10 '23 15:10 SobhanMP