Understanding Python type-checking edge cases
This is a medium-difficulty Python question that tests your grasp of type annotations and how static type checkers (like mypy) enforce them. Rather than executing code, you must reason about what a typechecker will accept—a skill essential for writing type-safe Python in production environments.
The question asks you to identify the correct type annotation or expression that satisfies the typechecker's constraints. This requires understanding the interaction between variable types, function signatures, and how type checkers validate assignments and function calls. You may need to consider union types, optional types, or protocol violations—or recognize when no valid annotation exists.
- Type inference and explicit annotations
- Protocol compliance and structural typing
- Union and optional types
- Type-checker error reporting