LET'S BUILD TOGETHER

http://rocka.co

xergioalex

Sergio A. Florez

TECH LEAD && FULL STACK DEVELOPER

WHY MYPY? #1

Less cognitive load needed to work with our code. The types of parameters and return values are clearly stated and verified. No guessing, and no surprises.

WHY MYPY? #2

Realize mistakes early. If we return the wrong type, forget that a variable may be None, or accidentally redeclare a variable, the type checker will tell us.

WHY MYPY? #3

Data validation. We declare our data classes using attrs, which allows us to state the types of our attributes, as well as checking them at runtime. We may switch to Pydantic, which has better syntax.

WHY MYPY? #4

Avoid trivial unit tests. Type checking avoids the need to write and maintain trivial unit tests.

What Types we can use?

Basic Types:

int, str, dict, list, set, float etc.
 

Advanced typing introduced in python 3.5

  • Collections: Tuple, Dict, MutableMapping, List, NamedTuple, etc.
  • Composers: Union, Optional
  • Callable
  • Generics: TypeVar, Generic.

INTEGRATING MYPY TO DEVELOPMENT FLOW

DEMO TIME!

LET'S BUILD TOGETHER

http://rocka.co

xergioalex

Sergio A. Florez

TECH LEAD && FULL STACK DEVELOPER

¡MUCHAS GRACIAS!

Introduction to MyPy

By Sergio Alexander Florez Galeano

Introduction to MyPy

Little introduction to mypy to allow add typing to python code.

  • 840