Typing your Python code like a ninja!
summary
Covers concrete typing techniques and shows them working: uses overload with a single implementation to give precise return types (example: get_user with strict=True → User, strict=False → Optional[User]), applies generics and bounded TypeVar so double(x) preserves type but forbids Decimal, demonstrates TypeGuard narrows types so is_user(obj) lets the checker treat obj as User, uses TypedDict for kwargs to catch missing fields at type check time, and adds override decorator and typing.Self to prevent signature regressions; examples compile with mypy/pyright and sometimes need tweaks for real frameworks.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 1:09Basic type examples
- 2:36Overload for flexible types
- 4:23Generics in Python
- 6:30Generic classes
- 7:14Generic callables
- 9:02Type narrowing issues
- 10:05Type guard vs type is
- 12:09TypeDict for kwargs
- 14:14Overrides in inheritance
- 16:42Typing self in builders
- 19:36Final ninja example
- 20:17Q&A session
related talks
29mGetting Started with Statically Typed Programming in Python 3.10
28mGradual Typing in Python
16mTyping in Python: Bringing Clarity, Safety, and Speed to Your Code
57mWhy You Should Care About Types
35mStatic Typing in Python
23mGradual Typing in Python
32mStatic Typing in Python
27m"How to Use Static Typing in Python with Type Hints, MyPy and Pydantic"
