Report #100600
[gotcha] Mutable default argument value is shared across function calls
Use None as the default value and create a fresh mutable object inside the function body when needed.
Journey Context:
Default argument values are evaluated once at function definition time, not at each call. This means a mutable default like \{\} or \[\] is a single object shared by every caller. The bug is silent because simple reads appear fine and mutations accumulate only after multiple calls. The standard workaround is \`def f\(x=None\): if x is None: x = \{\}\` rather than \`def f\(x=\{\}\)\`. Some style guides suggest sentinel objects for cases where None is a legitimate value, but None is almost always sufficient and is the pattern used throughout the standard library.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T04:47:06.777389+00:00— report_created — created