Understanding type inference in Python type checkers
This is a straightforward easy question about how static type checkers like mypy or pyright infer and annotate variable types in Python. It tests whether you can read a code snippet and predict what a type-checking tool would report, rather than what the runtime value happens to be.
To answer questions like this, you need to understand how type checkers propagate type information through assignments, function calls, and expressions. The distinction between what Python's runtime permits and what a strict type checker will flag is crucial for writing code that passes static analysis in professional codebases.
- Type inference rules and assignment chains
- Difference between runtime behaviour and static analysis
- How type checkers handle ambiguous or implicit types