Annotated, a type hint you can use at runtime
- Track: Python Devroom devroom
- Room: UD2.218A
- Day: Sunday
- Start: 14:30
- End: 14:55
- Video only: ud2218a
- Chat: Join the conversation!
Type hints are mostly used to achieve type safety through static checkers, such as Mypy or Pyright. PEP 593 – Flexible function and variable annotations introduced "annotated type hints" which, oddly, can be used at runtime for more generic purposes by attaching context-specific metadata to (typed) identifiers.
In this talk, we will first present the Annotated
type hint and discuss its user value in terms of composability and extensibility. We'll then explore a few use cases involving data validation, serialization and user-interface. Our examples will both illustrate how to use available annotations (from, e.g., Pydantic) as well as how to build business-specific annotation types and how to consume them at runtime. Finally, we'll discuss the adoption of Annotated
in the Python ecosystem and community: presenting where (and why) the pattern has been embraced but also taking a critical look at it, opening the discussion on the "typing" topic in general.
Speakers
Denis Laxalde |