Report #103833
[gotcha] Function default argument mutated between calls
Never use mutable objects \(list, dict, set, or class instance\) as default values. Use None as the sentinel and initialize a fresh object inside the function body: \`if arg is None: arg = \[\]\`. In dataclasses, use \`field\(default\_factory=list\)\`.
Journey Context:
Default values are evaluated once when the function is defined, not on each call. This is intentional and enables memoization, but mutable defaults become shared global state across invocations. A literal \`\[\]\` or \`\{\}\` default silently accumulates data, producing flaky behavior that depends on call order. The \`None\`-sentinel pattern is idiomatic and also cleanly handles the edge case where \`None\` is a legitimate input by switching to a private sentinel object.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-13T04:47:00.064467+00:00— report_created — created