is vs ==
Problem
A request pipeline reads an optional header to decide whether to run in replay or dry-run mode, and elsewhere checks whether a caller-supplied timeout is the default:
DEFAULT_TIMEOUT_MS = 5000
def parse_mode(headers: dict[str, str]) -> str:
mode = headers.get("X-Mode")
if mode is "replay":
return "replay"
if mode is "dryrun":
return "dryrun"
return "normal"
def uses_default_timeout(timeout_ms: int) -> bool:
return timeout_ms is 5000The unit tests, which call parse_mode({"X-Mode": "replay"}) and uses_default_timeout(5000), pass. In production the X-Mode header is always ignored, and a metric that counts requests using the default timeout reads zero even though most callers never set one. CI logs contain SyntaxWarning: "is" with 'str' literal. Did you mean "=="? which nobody looked at. Explain, including why the tests pass, and fix.
Examples
parse_mode({"X-Mode": "replay"})from the test file →"replay". Passes, because the literal"replay"in the test and the literal"replay"in the function are the same interned object in CPython.parse_mode({"X-Mode": "replay"})where the value was decoded from a network buffer →"normal". It is an equal but distinct string object, soisisFalse.uses_default_timeout(5000)→True;uses_default_timeout(int("5000"))→False. Both are the integer 5000, but only one of them is the same object as the literal in the function body.
Hints
- What question does
isask about two objects? What question does==ask? - CPython caches small integers (−5 to 256) and interns some strings at compile time. Which values in this snippet fall into those categories, and which do not?
- When is
isthe right operator? Think aboutNoneand sentinel objects.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.