Report #6575
[gotcha] Dataclass instances share mutable default values unexpectedly
Use \`field\(default\_factory=list\)\` \(or dict, set, etc.\) instead of \`default=\[\]\` for mutable dataclass fields
Journey Context:
Unlike regular classes where \`def \_\_init\_\_\(self, x=\[\]\):\` is the anti-pattern, dataclasses generate \`\_\_init\_\_\` from field definitions. Using \`default=\[\]\` creates the list at class definition time, making all instances share the same list object. \`default\_factory\` ensures the callable is invoked per instance during initialization, creating distinct objects. This is the dataclass-specific equivalent of the mutable default argument gotcha.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:22:24.080225+00:00— report_created — created