14:30 – 15:00
12 October 2022 | 30 Minutes
Paid
Special Session: Runtime Libraries using Python Annotations
With their initial inclusion in Python
3.0, annotations grew a variety of uses. Since PEP-484 in 2014, and with
subsequent expansions of gradual static typing support in the language, type
checking has become the predominant and ""official"" use
for annotations. The most visible such use is in static type checkers. Over
this same period, however, a number of widely used and powerful libraries have
also grown runtime uses for annotations. In the main, these libraries also
utilize annotations for typing purpose, but the nuances of typing sometimes
vary between runtime enforcement or hinting and static lint-like analysis of
whole programs.Both static and runtime type checking can be
useful for Python programs and libraries. Ideally, the same annotations can be
used for both purposes, but in edge cases this fails. Runtime libraries also
commonly express interfaces to external programs in a manner static checks
cannot, and also sometimes are able to detect and prevent runtime conditions
that are not always accessible to static analysis. Among libraries that use
annotations for runtime purposes are dataclasses, attrs (structured data, not enforced typing), typer
for CLI interfaces, SQLModel. odmantic, and Beanie for database interaction, Pydantic, and FastAPI for JSON microservices (and other uses),
and the use of annotations in documentation systems like Sphinx.