You have opted to be notified for this course. You will receive an email when the course becomes available.
92 Enrolled
24 Lessons
It should be no surprise that Python is a dynamically typed language. And
indeed, having dynamic types in your code is one of the best features of
Python. But dynamic types has its own problems as well, as it takes away a
great feature that statically typed languages like C++ and Java provide: You
can't accidentally pass the wrong types in them. If you pass an integer where
a string is expected in Java, your code won't compile. But in Python, your
code will start just fine, until it crashes with a TypeError while running.
Wouldn't it be great, if you could optionally write types in Python, to get
the same type checking guarantees that statically typed languages have? Mypy
lets you do exactly that!
Mypy is Python's official type checker. It's a really valuable and mature tool
that interacts seamlessly with Python, to provide really powerful features
like type safety, null safety, static duck typing, and generics, allowing you
to have your Python code checked with a solid type system.
Mypy Primer will take you from knowing nothing about mypy, to being able to
skillfully implement static type checking in your projects.
We'll see what kind of errors mypy will throw at you, how to configure mypy
to make the best use of it, and try to figure out what its errors mean.
Why doesn't mypy show an error here?
Mypy configuration
Simple type checking examples
Using reveal_type() to debug types
Mypy types, and the typing module
Modern Python has a LOT of type checking features baked into it. In this
chapter we will see a glimpse of what the typing module has to offer.
Lists, Dictionaries, and other collections
Union and Optional types
Reading mypy error messages
Type checking your classes
Typing *args and **kwargs
The "Any" type
Diving deep into the typing module
The typing module also provides various functions and base classes, that
create the basis of a lot of concepts of mypy's type system. In this chapter
we will dive deep into these functionalities.
Static duck typing
Custom Generic types
The NamedTuple class
The TypedDict class
Function overloading with @overload
Some advanced type checking concepts
In this chapter we will learn some concepts, tips and tricks on how to
properly type-check code using some of the more complicated Python concepts.
Type checking decorators
Type checking generators
The Type type
Conclusion
In this chapter, we will wrap up the series, and understand where type
checking sits in the ecosystem of Python, and your software development
process.
Type checking, or writing tests? Why not both!
Integrating mypy into your software development lifecycle
Not Available for Preview
This lesson is not available for preview. Please join the course to access it.