What this Python type-checking interview question tests
This is a medium-difficulty question that probes your understanding of how modern Python type-checkers infer and reason about types, particularly in situations where the type system's logic may diverge from runtime behaviour. It's the kind of question that separates candidates who use type hints casually from those who understand the formal rules underneath.
To answer correctly, you need to trace through the code mentally as a static type-checker would—following assignments, function signatures, and type narrowing rules rather than simulating runtime execution. The question rewards precision: understanding what information the type-checker has available at each step, how it handles ambiguity, and which inferred types it will assign to a given variable.
- Type inference and annotation rules
- Type narrowing and control flow analysis
- Distinguishing static type-checker logic from runtime semantics