Report #62023
[gotcha] Why does my function's default list argument share state between calls?
Use \`None\` as the sentinel default and initialize the mutable object inside the function body. Type hint as \`Optional\[List\[T\]\] = None\`.
Journey Context:
Python evaluates default arguments once at function definition time, not at call time, creating a single shared mutable object for all invocations. The \`None\` sentinel pattern avoids this by moving initialization to runtime. This is particularly insidious with type checkers: \`list = \[\]\` looks correct but is wrong; \`Optional\[list\] = None\` is the idiomatic annotation that signals the runtime initialization pattern to readers and static analysis tools.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:35:29.241851+00:00— report_created — created