4. Better
Developer Experience
No guessing & no surprises
Less cognitive load
Type checking at commit &
build time
Realize mistakes early
Type checks are easier to
write & maintain
Avoid trivial unit tests
Type checking at runtime
with Pydantic
Data validation
6. What types can I use?
Collections
Tuple, Dict, MutableMapping,
List, NamedTuple...
Composers
Union, Optional
Callable
Generics
TypeVar, Generic, Protocol
...and all simple types
int, str, bytes...
7. Checks: Green
No more
typing issues
Add typing
to new code
Add typing
on existing code
How did we introduce type checks?
Make the changes needed
to have mypy run
without errors.
Add a mypy step to your
CI build and
pre-commit hooks.
From now onwards, no new
typing problems can be
introduced.
Things can only get better!
Teach your team
about typing and mypy.
Agree on adding type hints
to all new code.
Gradually add type hints
to all existing code.
If you touch it,
you add types.
8. Pitfalls
False sense of security
It wont catch all issues.
No runtime checks.
Type checking: an extra safety step,
not a replacement.
No optimizations
Python wont use the knowledge
about types to make any
optimizations on your code.
Untyped libraries will lead to typing
mistakes.
Type hints can get ugly
Tip on that is: if your type is ugly, is
there a better approach?
24. Type checkers
Reference implementation.
We use it at Tiqets
mypy
Faster; runs on nodejs.
pyright (Microsoft)
Can infer types from
unannotated code.
pytype (Google)
Can do incremental checking
pyre (Facebook)
25. Whats
coming up?
Uni鍖ed error codes
Easier integration of type checkers
with other tools
Less CamelCase
list[dict] instead of List[Dict]
Shorter syntax
int | float instead of Union[int, float]
?str instead of Optional[str]