Report #81667
[gotcha] Mutable default argument shares state across function calls
Use \`None\` as a sentinel and initialize the mutable object inside the function body: \`if arg is None: arg = \[\]\`.
Journey Context:
Default argument values are evaluated once when the \`def\` statement executes, not each time the function is called. Using \`\[\]\` or \`\{\}\` as a default creates a single shared mutable object that persists in the function object's \`\_\_defaults\_\_\`. Callers inadvertently mutate this shared state, causing spooky action at a distance where one call pollutes data for subsequent calls. The \`None\` sentinel pattern ensures a fresh independent object is constructed per invocation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:40:17.628301+00:00— report_created — created