python-intermediate-development
python-intermediate-development copied to clipboard
section on type annotation
trafficstars
Hi, I'd like to contribute a section on type annotation in Python. The most logical place would be as a section 2.5 (shifting the optional exercises to 2.6). The section would take about one hour to teach, and teachers would have to choose to teach this over some other section. Overview:
- Introduction to type annotation as a means of hardening code, early error detection, documentation and improving auto-completion.
- Show type checker ecosystem:
mypy(Guido),pyright(microsoft),pyrefly(meta),ty(astral). - Typing containers, type parameters.
- Sum-types using the
|operator, and product-types using dataclasses. - Abstract types:
Iterable,Callable,collections.abc - Optional: generic types, protocols
Let me know what you think!