Exploring Function Annotations
summary
Shows how Python function annotations become machine-readable metadata and how the standard library typing plus the static checker mypy catch wrong-call types, demonstrate Optional/Union to accept None or multiple types, and use an annotation-driven convert function that coerces inputs and outputs (strings→ints→bools) so a single implementation accepts varied encodings. Examples include annotating returns that can be None, mypy errors for incompatible calls, and a practical converter used for mathematical helpers that normalizes incoming data before running core logic.
AI-written summary · about
chapters (8)
- 0:00Introduction to docstrings
- 3:00Function annotations basics
- 5:04Accessing annotation data
- 6:59Static type checking with Mypy
- 8:53Handling optional return types
- 10:34Advanced typing with Union
- 12:26Using annotations for runtime
- 16:24Conclusion and Q&A
related talks
12mType Annotations in Python: Terribly Intimidating or Tremendously Informative?
30mStatic type checking with mypy
29mPython Type hints and how they can supercharge CS education.
32mType-checked Python in the real world
38mMigrating existing codebases to using type annotations
28mGradual Typing in Python
16mTyping in Python: Bringing Clarity, Safety, and Speed to Your Code
57mWhy You Should Care About Types
