Report #104230
[gotcha] Using mutable default value \(list, dict\) in a dataclass field leads to shared state across instances
Use \`field\(default\_factory=list\)\` or other factory for mutable defaults; never use \`= \[\]\` or \`= \{\}\` directly.
Journey Context:
In dataclasses, the default value is evaluated once at class definition time, not per instance. This is identical to the mutable default argument footgun in functions. Many developers mistakenly think dataclasses handle this automatically because they generate \_\_init\_\_, but they don't. Using \`field\(default\_factory=...\)\` ensures each instance gets a fresh mutable object. The alternative is to use an immutable sentinel like \`None\` and initialize in \`\_\_post\_init\_\_\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:05:00.969592+00:00— report_created — created