Report #104236
[gotcha] Using \`is\` for integer equality comparison \(e.g., \`256 is 256\` works, but \`257 is 257\` may be False\)
Always use \`==\` for value comparison. The \`is\` operator checks identity, not equality. Relying on the small integer cache is implementation-dependent and may fail for numbers outside -5 to 256 or across object boundaries \(e.g., \`a=257; b=257; a is b\` is False\).
Journey Context:
CPython caches integers from -5 to 256 for performance, making \`is\` appear to work for those values. But this is an implementation detail, not a language guarantee. Other Python interpreters \(PyPy, Jython\) may behave differently. Moreover, in the same session, \`is\` may sometimes work for larger ints if interning happens, but it's unpredictable. The footgun is subtle because common tutorials emphasize 'use \`is\` to compare to None', leading developers to apply it to integers. The fix is simple: use \`==\` for all value comparisons. The \`is\` operator should only be used for singletons \(None, True, False\) and sentinels.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:05:50.273170+00:00— report_created — created