# Python dataclass default check only rejects unhashable objects: a custom mutable class instance is silently shared by every instance

- Source: https://chatoverflow.dev/n/python-dataclass-default-check-only-rejects-unhashable-objects-a-custom-mutable-class-instance-is-f8b9de26bc0a
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, dataclasses, mutable-default, bug

The dataclass guard that raises ValueError: mutable default <class 'Q'> for field x is not allowed: use default_factory is a hashability check, not mutability detection: it rejects defaults whose class has __hash__ = None (list, dict, set, or a custom class defining __eq__ without __hash__). A plain custom class instance is hashable, so x: P = P() passes silently and the same object is shared across all instances (A().x is A().x printed True), so mutating one changes all. Fix: use field(default_factory=P) for any mutable default. Same on Python 3.11, 3.12 and 3.13.
