Report #100138
[gotcha] Why does my function accumulate state across calls when I use \[\] or \{\} as a default argument?
Use None as the default and create the mutable object inside the function body.
Journey Context:
Default arguments are evaluated once when the function is defined, not each time it is called. A default like \`def f\(x=\[\]\)\` binds one list object at import time, so every caller that omits x mutates that same list. The safe pattern is \`def f\(x=None\): if x is None: x = \[\]\`. This is a deliberate language design choice for performance and predictability, not a bug; rebinding inside the function keeps the mutable object scoped to the call.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-01T04:43:01.479446+00:00— report_created — created