Report #94076
[gotcha] Mutable default arguments share state across function calls
Use None as the default sentinel and initialize the mutable object inside the function body with \`if x is None: x = \[\]\`
Journey Context:
Python binds default argument values exactly once when the function is defined, not each time it is called. This causes the object to persist and mutate across calls. A common mistake is using \`x or \[\]\` instead of \`if x is None\`, which incorrectly treats falsy values like empty strings or zero as signals to create a new list. Using \`is None\` is the only way to distinguish between 'no argument passed' and 'falsy argument passed'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:29:42.821327+00:00— report_created — created