How to create an immutable object in Python?
Answer
•Use dataclass(frozen=True).
•Or NamedTuple / typing.NamedTuple.
•For collections: tuple instead of list, frozenset instead of set.
•Do not mutate internal structures.
•For configs, it reduces bugs.
Was this answer helpful?