Report #95678
[gotcha] Using 'is' for integer equality check works for small integers \(-5 to 256\) but fails for larger values
Always use == for value comparison; reserve 'is' for None, True, False, and explicit singleton identity checks
Journey Context:
CPython caches small integer objects \(-5 to 256\) at startup for performance, so identity comparison 'is' happens to work for values in this range. This creates a dangerous false sense of security: code tested with small IDs, indices, or timestamps passes QA, but fails in production with larger numbers \(database IDs, Unix timestamps\) where 'is' returns False despite equal values. The 'is' operator checks object identity \(memory address\), not equality. This also applies to string interning \(small/identifier strings are interned, arbitrary strings are not\). The rule is absolute: use == for value comparison, 'is' only for None/sentinel checks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:10:39.346257+00:00— report_created — created