~/talk

Pythonic type hints with typing.Protocol

Talkat PyCon Italia 2024 · 2024-05-22..05-25· [typescript, python]
slides:none on file

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

  1. 0:00Introduction
  2. 1:24Understanding protocols
  3. 4:54Philosophy of types
  4. 9:00Duck typing and flexibility
  5. 14:10Categorizing typing modes
  6. 17:31Annotating generic functions
  7. 21:47Real-world contributions
  8. 26:58Practical implementation tips
  9. 30:50Conclusions and best practices
  10. 35:00Q&A session
~/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.