Report #9736
[gotcha] Identity operator \`is\` succeeds for small integers by implementation accident, failing in production with larger numbers
Always use \`==\` for numeric equality. Reserve \`is\` strictly for \`None\`, sentinel objects, and identity checking where object uniqueness matters, never for value comparison.
Journey Context:
CPython interns small integers \(-5 to 256\) at startup for performance, causing \`x is 5\` to accidentally work when x is 5. In production, calculations producing integers outside this range \(e.g., large IDs, arithmetic results\) create distinct objects, so \`x is 1000\` fails even if \`x == 1000\`. This creates heisenbugs that pass in tests with small IDs but fail in production. The \`is\` operator checks object identity \(memory address\), not equality. While tempting for micro-optimizations or None checks, it is fundamentally incorrect for value comparison.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:53:21.688991+00:00— report_created — created