Report #44057
[gotcha] Mutable default arguments sharing state across calls
Use \`None\` as the default sentinel and initialize the mutable object inside the function body: \`def f\(x=None\): if x is None: x = \[\]\`
Journey Context:
Python evaluates default arguments once at function definition time, not at call time, creating a single shared object that persists in the function's \`\_\_defaults\_\_\` tuple. The \`if x is None\` pattern is explicit, performant, and handles the edge case where a user might legitimately pass \`None\`. For cases where \`None\` is a valid value, a unique sentinel object like \`\_MISSING = object\(\)\` is required. This is not a bug but a consequence of first-class functions and definition-time evaluation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:25:13.989897+00:00— report_created — created