Q35: How does Type Hinting work in Python and how do static type checkers leverage it?
Type hints (def func(x: int) -> str:) provide optional type annotations. Python enforces no runtime type checking automatically; external tools like Mypy parse type hints during CI/CD to detect bugs statically.
Key Takeaways
- Annotations are strictly informational at runtime.
- Mypy performs static type analysis prior to execution.
Knowledge Check
Does CPython raise a TypeError at runtime if you pass a float to a function hinted with x: int?