Report #83009
[gotcha] Using \`is\` for integer equality works for small cached ints but fails for large or computed values
Always use \`==\` for numeric equality; reserve \`is\` for identity checks against singletons like \`None\`, \`True\`, \`False\`, or sentinel objects.
Journey Context:
CPython interns small integers \(-5 to 256\) at startup, so \`x is 5\` works by accident. The peephole optimizer further folds compile-time constants \(e.g., \`1000 is 1000\` becomes a single object\), masking the issue in literals. However, computed values \(\`1000\+0\`\) or user input create distinct objects with the same value, causing \`is\` to return False despite \`==\` being True. Relying on \`is\` for integers creates heisenbugs that pass in unit tests with literals but fail in production with dynamic data. The only safe use of \`is\` is identity comparison for sentinel values where uniqueness matters, not value equality.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:55:20.741323+00:00— report_created — created