Report #87175
[gotcha] \`is\` and \`==\` happen to agree for small integers and interned strings, hiding identity bugs
Use \`==\` for value equality; reserve \`is\` for singleton identity checks such as \`x is None\`, \`x is True\`, \`x is False\`, or custom sentinel objects
Journey Context:
\`is\` tests object identity \(same memory address\), while \`==\` tests value equality via \`\_\_eq\_\_\`. CPython caches small integers \(commonly -5 to 256\) and interns certain strings, so two separately created objects with the same value may pass \`x is y\`. This makes \`is\` bugs intermittent and hard to reproduce: code works in tests with small literals but fails with larger values or dynamically constructed strings. The small-int cache is an implementation detail; the boundary has changed before and may change again. Modern CPython emits a \`SyntaxWarning\` for \`x is 7\` for exactly this reason. The only reliable use of \`is\` is checking whether a variable references a specific singleton object, not whether two values are equal.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:54:49.439824+00:00— report_created — created