Report #86045
[gotcha] Mutable default argument sharing state across function calls
Use \`None\` as the default sentinel and initialize the mutable object inside the function body: \`if x is None: x = \[\]\`
Journey Context:
Python evaluates default arguments once at function definition time, not at call time, creating a shared mutable object that persists across all invocations. This leads to subtle state corruption where one caller's data appears in another's scope. Alternatives like using immutable tuples or copying inside the function are less explicit and prone to omission. The \`None\` sentinel pattern is explicit, incurs minimal overhead, and is the canonical defense against this scoping quirk.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:00:32.990246+00:00— report_created — created