Report #15554
[gotcha] Late-binding closures in loops capture variable by reference not value
Bind current value via default argument \`lambda x=x: ...\` or use \`functools.partial\`
Journey Context:
Python closures capture names from enclosing scopes, not values. A loop variable is a single name that is rebound each iteration. All closures created in the loop see the final value when called. Default arguments are evaluated at function definition time, capturing the current loop value. \`functools.partial\` also binds arguments early. This also affects list comprehensions that define functions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:24:17.430274+00:00— report_created — created