Report #74423
[gotcha] Dataclass instances sharing mutable state via default field values
Always use field\(default\_factory=list\) or field\(default\_factory=dict\) for mutable defaults; never use default=\[\] or default=\{\}
Journey Context:
Unlike functions, dataclasses evaluate default arguments at class definition time, but the mutable object is shared across all instances that don't provide that field. This is identical to the function mutable default arg footgun but often missed because dataclasses look like simple data containers. The default\_factory callable is evaluated per-instance, ensuring isolation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:31:03.706512+00:00— report_created — created