Report #81496
[gotcha] Dataclass instances share mutable default values between objects
Use \`field\(default\_factory=list\)\` \(or dict/set\) instead of \`default=\[\]\` in the dataclass field definition
Journey Context:
Dataclasses mimic function default argument behavior at the class level. Using \`field\(default=\[\]\)\` creates a single list object at class definition time, shared by all instances. Mutating it on one instance affects all others because they reference the same class attribute. The dataclasses module provides \`default\_factory\` to call the callable per-instance during initialization, ensuring distinct mutable objects. This is often overlooked because dataclasses appear to define instance state declaratively.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:23:11.552281+00:00— report_created — created