What this Python type-checking question tests
This is a hard Python question that probes your understanding of how modern type checkers—like mypy or Pyright—infer and report types in non-obvious scenarios. It rewards deep familiarity with Python's type system, including how checkers handle edge cases that can surprise even experienced developers.
Working through this question requires you to trace how a type checker analyzes code, paying close attention to type narrowing, union types, and the distinction between what the runtime does and what static analysis concludes. You will need to reason about what information the checker has at each step and how it represents types in its output.
- Type inference and type narrowing
- Union types and type guards
- Type checker output conventions and namespace representation
- Distinction between runtime behavior and static type analysis