Elastic Generics: Flexible Static Typing with TypeVarTuple and Unpack
summary
TypeVarTuple and Unpack make generics variadic so a class can be parameterized as Record[int, str], Record[int, str, float], or Record[int, str, tuple[float, ...]] and mypy statically validates those shapes. Python 3.11 adds the TypeVarTuple primitive and 3.12 simplifies declaration syntax. StaticFrame ships a comprehensively generic DataFrame that models a fixed heterogenous prefix and a variable uniform suffix, offers a runtime checker and relies on mypy validation*. Limitation: only one unpack region per generic.
AI-written summary · about
chapters (11)
- 0:00Elastic generics intro
- 1:49Elemental and generic types
- 4:42Traditional generics limits
- 6:49TypeVarTuple and Unpack
- 9:17Flexibility of tpple
- 11:07Advanced tpple use cases
- 14:39Defining generics with TypeVarTuple
- 18:34TypeVar and TypeVarTuple
- 20:00Generic data frames
- 26:01Why elastic generics matter
- 27:22Q&A
related talks
35mStatic Typing in Python
30mStatic type checking with mypy
22mStatic Typing in Python
16mTyping in Python: Bringing Clarity, Safety, and Speed to Your Code
32mStatic Typing in Python
29mGetting Started with Statically Typed Programming in Python 3.10
27m"How to Use Static Typing in Python with Type Hints, MyPy and Pydantic"
23mGradual Typing in Python
