Understanding Python type inference in nested function contexts
This is a medium-difficulty Python typing question that tests your ability to read and reason about how static type checkers infer types in realistic code. It rewards precision in understanding scope, assignment, and how type narrowing works across function boundaries.
To answer questions like this correctly, you need to think like a type checker: trace the flow of assignments, consider what information is available at each point in the code, and recognize when a checker must fall back on a broader type or union. The question pushes you to distinguish between what the code does at runtime and what a static analyzer can prove from the source alone.
- Type narrowing and control flow analysis
- Local vs. module scope in type inference
- How type checkers handle reassignment and conditional logic