Report #102002
[gotcha] Function with mutable default argument \(list/dict\) shares state across 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 on each call. The resulting object is attached to the function object and reused, so mutable defaults act like hidden global state. The idiomatic fix is to default to None and assign the mutable in the body; this preserves per-call isolation without changing the function signature. Avoid custom sentinel objects unless you genuinely need to distinguish 'not passed' from 'None passed'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-08T04:48:30.566821+00:00— report_created — created