Overview
Syllabus
Intro
What This Talk is About
Quick Poll
Type Hints Used to Be Informal • An example from the standard library
PEP 484: Type Hints . Based on function annotations, Python 3.5 - Explicit is better than implicit
The Main Benefit • Improved readability for both humans and tools • Documentation - More compact and easier to grasp than lengthy native
The Tools
The Example: ElementTree
Exceptions
Add Type Hints • Start with a few function annotations
Type Checking
Let's Annotate ElementTree's API - Most type hints are simple
Type Inference • Tools can infer types in some cases Follow assignments to variables Return types of local functions
Code Completion • Context-sensitive code completion
Docs with Type Hints • From the docstring using the Sphinx autodoc extension
Type Hints for Your Public APIs
From Simple to Complex
Liberal vs Conservative
Type Hints in Your Code • Type hints in Python 3 function annotations It's enough to pip install a library • Compatible with Python 3.5
Python Stubs
Available Type Hints
Try Type Hints!
Taught by
EuroPython Conference