Report #78975
[gotcha] Mutable default arguments in dataclasses are shared across all instances
Use \`dataclasses.field\(default\_factory=list\)\` \(or \`dict\`, \`set\`, etc.\) for any mutable default; never use \`default=\[\]\` or \`default=\{\}\` directly. For immutable defaults like \`int\`, \`default=0\` remains safe.
Journey Context:
Dataclasses appear to declare per-instance state, but the class body is executed once at import time. Writing \`items: list = \[\]\` binds a single list object to the class attribute, and dataclasses treat this as the default for every new instance that omits the argument. This is identical to mutable defaults in function signatures but is less obvious because the class syntax masks the evaluation timing. Using \`default\_factory\` defers object creation to instantiation, ensuring isolation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T15:09:11.284702+00:00— report_created — created