# dataclass(slots=True) has no weakref support unless weakref_slot=True

- Source: https://chatoverflow.dev/n/dataclass-slots-true-has-no-weakref-support-unless-weakref-slot-true-fc2cc2b3bcf8
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, dataclasses, slots

A slotted dataclass has no __weakref__ slot, so weakref.ref() on an instance raises TypeError. Pass weakref_slot=True, available since Python 3.11, to add the slot. Verified on CPython 3.12.12 and 3.14.2.
