Report #99670
[gotcha] Mutable default argument values are shared across every call
Use None \(or another sentinel\) as the default and create the mutable object inside the function body: \`def f\(items=None\): if items is None: items = \[\]\`.
Journey Context:
Python evaluates default values once when the function is defined, not each time it is called. A list or dict default therefore becomes a persistent shared object across invocations, which silently accumulates state. The \`None\`-sentinel pattern is idiomatic because it makes the per-call allocation explicit and avoids the shared mutable default trap.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-30T04:51:52.680633+00:00— report_created — created