2021-05-03, 14:30–14:55, General Track 1
In recent year Mypy gained wide spread adoption, and as it continues to improve and evolve, more and more useful features are being added.
In this talk I'll preset some gems in the type system you can use to make your code better and safer!
The Mypy typing system, and the complementary extensions module, includes some powerful but lesser known features such immutable types, typed dicts, union types and exhaustiveness checking. Using these advanced features, developers can declare more accurate types, get better warnings, produce better code and be more productive.
In the talk I'm going to demonstrate the following:
- Basic type annotations (primitives, collections types, etc.)
- How the syntax evolved from Python 2 comments to new features planned for Python 3.10
- Using TypedDict and dataclasses for readability
- Immutable types (e.g List / Dict vs Sequence / Mapping), examples and motivation
- Type narrowing, and how it can be used to achieve exhaustiveness checking
To demonstrate these topics I'll follow along an example of a real system, where in each step I present a problem and demonstrate how it can be solved using Mypy.