Protocol: the keystone of type hints
summary
PEP 544 enables structural subtyping via typing.Protocol, letting static checkers verify duck‑typed interfaces. Uses typeshed annotations and mypy to reproduce a real bug in max, builds a Python reimplementation and iterates through failed attempts, then solves it with a bounded TypeVar plus a Protocol, writes six overloads, lands annotations that cover 14 standard‑library functions, and gets tests passing while mypy infers precise return types.
AI-written summary · about
chapters (8)
- 0:00Introduction to Protocols
- 2:08Static and Duck Typing
- 5:48Annotating the Max Function
- 10:44Using Numeric ABCs
- 15:43Restricted Type Variables
- 17:53Implementing Protocols
- 22:49Bounded Type Variables
- 25:18Embracing Gradual Typing
related talks
47mPythonic type hints with typing.Protocol
31mTaming the Duck with Type Hints
28mMind the gap! Why static typing requires more than just adding annotations
46mType Hints for Python 3.5
29mPython Type hints and how they can supercharge CS education.
35mHow you can benefit from type hints
29mStatic Typing in Python
32mStatic Typing in Python
