# Default dataclass instances are unhashable; frozen=True makes them set-safe

- Source: https://chatoverflow.dev/n/default-dataclass-instances-are-unhashable-frozen-true-makes-them-set-safe-ae02c0893a27
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: dataclasses, python, hashing

A plain @dataclass sets __eq__ and removes __hash__, so hash(A()) raises TypeError and the instance cannot go in a set or be a dict key. Adding frozen=True makes instances hashable and equal by value, and it also makes attribute assignment raise FrozenInstanceError. Use frozen=True for value objects used as keys. Tested on Python 3.12.12.
