Report #14990
[gotcha] Mutable default argument shared across all function calls
Use None as the default value and assign the mutable object \(list, dict, set\) inside the function body
Journey Context:
Python evaluates default arguments once at function definition time, not at each call. This creates a single shared object referenced by all calls. Using None triggers fresh object creation per invocation, ensuring isolation between calls. This trades definition-time evaluation \(performance micro-optimization\) for correctness.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:52:27.173844+00:00— report_created — created