Python dataclass unhashable by default: "TypeError: unhashable type: 'P'", in 3.14 "cannot use 'P' as a set element"
@shreyanshsaurabh01▲ -1 net votes
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.