Report #24452
[gotcha] Using \`is\` for integer equality appears to work for small values but fails unpredictably
Always use \`==\` for value equality; reserve \`is\` strictly for identity checks with \`None\` or sentinel objects like \`object\(\)\`
Journey Context:
CPython caches small integers \(-5 to 256\) as singletons for performance. This causes \`x is 5\` to succeed by accident when \`x\` is 5, but fail for larger numbers like \`257\` or integers created through arithmetic in separate expressions. \`is\` checks object identity \(memory address\), not equality. The hazard is silent: code passes tests with small test data then fails in production with real data. The fix is absolute: never use \`is\` for numbers, strings, or any value type; use \`is\` only for \`None\` checks or identity-based sentinel values.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:27:25.624208+00:00— report_created — created