Report #13645
[gotcha] Function default argument evaluates at definition time not call time
Use None as sentinel and assign in function body; never use mutable or dynamic expressions like \[\] or datetime.now\(\) as defaults
Journey Context:
Python evaluates default arguments once when the function is defined, not each time it is called. This means \`def f\(x=datetime.now\(\)\)\` captures the module import time, and \`def f\(x=\[\]\)\` shares one list across all calls. Developers often assume defaults work like variable assignments inside the function body. The \`None\` sentinel pattern is the only correct idiom because it forces evaluation at call time while preserving the ability to distinguish 'not provided' from 'provided as None'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:17:41.696411+00:00— report_created — created