python-intermediate-development icon indicating copy to clipboard operation
python-intermediate-development copied to clipboard

section on type annotation

Open jhidding opened this issue 5 months ago • 1 comments
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:

  1. Introduction to type annotation as a means of hardening code, early error detection, documentation and improving auto-completion.
  2. Show type checker ecosystem: mypy (Guido), pyright (microsoft), pyrefly (meta), ty (astral).
  3. Typing containers, type parameters.
  4. Sum-types using the | operator, and product-types using dataclasses.
  5. Abstract types: Iterable, Callable, collections.abc
  6. Optional: generic types, protocols

Let me know what you think!

jhidding avatar Jun 19 '25 07:06 jhidding