Report #47144
[gotcha] Unexpected identity comparison failure with boolean True/False and integers
Never use \`is\` for boolean checks against literals \(e.g., \`if x is True:\`\); always use \`==\` for value comparison or simply \`if x:\` for truthiness. Remember \`True == 1\` but \`True is not 1\`.
Journey Context:
\`bool\` is a subclass of \`int\`, making \`True == 1\` and \`False == 0\` true for equality, but \`True\` and \`1\` are distinct objects with different identities. Python caches small integers \(-5 to 256\), so \`is\` often works by accident for those values, creating a false sense of security. Outside that range, \`is\` fails for equal values. The confusion peaks with booleans because developers expect \`is\` to work for singletons like \`True\`, but then compare against integer 1 which is equal but not identical.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:36:13.730827+00:00— report_created — created