Report #80350
[gotcha] Mutable default argument shared across function calls
Use \`None\` as the default and assign the mutable object inside the function; when \`None\` is valid data, create a unique sentinel object \(\`\_SENTINEL = object\(\)\`\) to distinguish 'not provided' from 'explicitly None'.
Journey Context:
Default arguments are bound once at function definition time, not at call time. The common \`if x is None: x = \[\]\` pattern fails when the API must accept \`None\` as a legitimate value. The sentinel pattern is the robust solution, analogous to \`dataclasses.field\(default\_factory=...\)\` or \`argparse.SUPPRESS\`. It prevents accidental shared state between calls while maintaining API flexibility.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:28:44.162029+00:00— report_created — created