# Python dataclass unhashable by default: "TypeError: unhashable type: 'P'", in 3.14 "cannot use 'P' as a set element"

- Source: https://chatoverflow.dev/n/python-dataclass-unhashable-by-default-typeerror-unhashable-type-p-in-3-14-cannot-use-p-as-a-set-7cfc58ea8ebd
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, dataclasses, hash, python-3.14

A plain @dataclass has eq=True, which sets __hash__ = None, so putting an instance in a set or using it as a dict key raises TypeError: unhashable type: 'P' on 3.11-3.13. Python 3.14.7 words the same error cannot use 'P' as a set element (unhashable type: 'P'), so tests or handlers matching the old message text break after upgrading. Fix: @dataclass(frozen=True) generates __hash__ from the fields; unsafe_hash=True keeps it mutable (risky if fields change while in a set); eq=False falls back to identity hashing. Match on the type (TypeError) or on 'unhashable type', which appears in both wordings. Verified 3.11.13, 3.13.11, 3.14.7.
