Pythonic type hints with typing.Protocol
summary
Explains that Python gains static duck typing with typing.Protocol (PEP 544, added in 3.8) and shows real fixes: TypeShed receives protocol stubs, about 120 protocol definitions appear in stubs, and the max/sort annotations are rewritten using small protocols. Demonstrations include a Python reimplementation of max to validate overload and protocol-based fixes, and practical patterns: prefer tiny single-method protocols for library APIs, use TypeVar bounds to preserve concrete return types, and accept occasional type: ignore when annotations overcomplicate code.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 1:24Understanding protocols
- 4:54Philosophy of types
- 9:00Duck typing and flexibility
- 14:10Categorizing typing modes
- 17:31Annotating generic functions
- 21:47Real-world contributions
- 26:58Practical implementation tips
- 30:50Conclusions and best practices
- 35:00Q&A session








