~/talk

Protocol: the keystone of type hints

Talkat PyCon US 2021 · 2021-05-14..05-15· [python]
slides:none on file

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

  1. 0:00Introduction to Protocols
  2. 2:08Static and Duck Typing
  3. 5:48Annotating the Max Function
  4. 10:44Using Numeric ABCs
  5. 15:43Restricted Type Variables
  6. 17:53Implementing Protocols
  7. 22:49Bounded Type Variables
  8. 25:18Embracing Gradual Typing
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.