Understanding Python type inference in typecheckers
This is a Cracked-level Python question that tests your familiarity with how modern typecheckers like mypy, pyright, and pydantic infer and assign types to variables. It's the kind of question that separates candidates who have hands-on experience with static type analysis from those who rely only on runtime intuition.
The question asks you to read a code snippet and predict what a typechecker would declare as the type of a given variable. This requires understanding type narrowing, union types, literal inference, and how typecheckers propagate type information through assignments and operations. Getting this right depends on knowing the specific rules and quirks of the typechecker in question, not just Python semantics.
- Type inference and type narrowing
- Literal types versus inferred types
- How typecheckers handle ambiguous or context-dependent expressions