Wednesday, September 25, 2024

Python dataclass annoyances

Apparently, it is not possible to inherit from an non-frozen class if you declare the derived class as frozen. That is weird and defeats the purpose!

At least the PyCharm Community Edition IDE flags it and would not allow it. Message: "Frozen dataclasses can not inherit non-frozen one and vice versa"

Why is the frozen option apparently not available at the field level?

It appears you can not use e.g. the __post_init__ to freeze the instance. Really bad. It seems you can also not use the typing.Final in the __post_init__.

Caveat: I am not an expert Python developer.

No comments: