Report #98753
[gotcha] Mutable default argument values are shared across all function calls
Use None as the default and initialize the mutable object inside the function body.
Journey Context:
Python evaluates default arguments once when the function is defined, not each time it is called. A mutable default like \`def f\(x=\[\]\)\` creates a single list object that persists as an attribute on the function object \(\`f.\_\_defaults\_\_\`\). Every caller that omits \`x\` mutates that same list. Alternatives such as a custom sentinel object or deep-copying inside the function work, but None is the idiomatic choice because it clearly signals 'not supplied' and avoids accidental sharing. This is a deliberate language design decision, not a bug, but it is the most common source of phantom-state bugs in Python.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:43:06.947909+00:00— report_created — created