Static type checking with mypy
summary
Mypy performs static checks on Python annotations with practical features: type inference so only parameters and returns need annotations, Union/Optional with type narrowing to avoid None errors, assert_never checks exhaustiveness for unions, and Protocols for structural typing. Examples include flagging passing a string where an int is expected and using NewType prevents ID mix-ups so company_id and order_id aren’t interchangeable. Problems include untyped third‑party libs and Any turning checks off; strict mode and CI integration mitigate those.
AI-written summary · about
chapters (13)
- 0:00Introduction to mypy
- 1:10What is mypy
- 2:13Type annotations basics
- 3:59Type inference in mypy
- 5:26Special types like NoReturn
- 7:14Union types and enums
- 9:47Type guards and narrowing
- 12:16Protocols and structural typing
- 14:47Generics in mypy
- 16:35New types for safety
- 19:50Problems with mypy
- 22:46Limitations and strict mode
- 23:06Q&A session
related talks
23mmypy Python's gradual typing implementation
31mStatic Type Analysis for Robust Data Products
27m"How to Use Static Typing in Python with Type Hints, MyPy and Pydantic"
32mStatic Typing in Python
46mHow to make a static type checker your best friend
29mStatic Typing in Python
30mTyping at scale: statically type-checking a large codebase
22mStatic Typing in Python
