Migrating existing codebases to using type annotations
summary
Shows how a large legacy Python codebase (tens or hundreds of thousands of lines) is incrementally annotated, enforced per‑file via pre-commit hooks, and type‑checked with mypy. Demonstrates generated typed models and client stubs from OpenAPI to catch mismatched network types, practical workarounds for namedtuple and descriptor quirks, typed dicts to eliminate silent key bugs, and limits like recursive types. Builds run‑time‑free checks that mostly work and surface surprising refactor needs.
AI-written summary · about
chapters (33)
- 0:00Introduction
- 0:30Yelp
- 0:50Talk Outline
- 2:30Code Example
- 4:00Migrating a bigger codebase
- 5:15Python type checker
- 6:20Enforce type annotations
- 8:00Precommit
- 8:30Precommit configuration
- 9:50Running precommit hooks
- 11:55Type your datum
- 13:25Dictionaries
- 15:25Type Data
- 15:50Instantiate
- 16:15NamedTuple
- 17:00Errors
- 17:50Class attributes
- 18:20Name tuples
- 19:05Solution
- 20:15Structural subtyping
- 20:45Named tuples
- 21:20Metaclasses
- 22:20Descriptor
- 24:10recursive types
- 24:25cast operator
- 25:00serviceoriented architecture
- 26:05confidence in changes
- 27:05API specification
- 27:35API model
- 28:55Generating typed annotations
- 29:30Generated code
- 31:45Example function
- 36:15Summary
related talks
30mTyping at scale: statically type-checking a large codebase
57mWhy You Should Care About Types
32mType-checked Python in the real world
28mGradual Typing in Python
03h 38mPython Types for Fun and Profit
31mStatic Type Analysis for Robust Data Products
30mClearer Code at Scale: Static Types at Zulip and Dropbox
30mStatic type checking with mypy
