-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Modern Python Cookbook - Third Edition
By :
Through a number of Python Enhancement Proposals, type hints have grown in sophistication. The mypy tool is one way to validate these type hints to be sure the hints and the code agree. All the examples shown in this book have been checked with the mypy tool.
This extra syntax for the hints is optional. It has limited use at runtime and has no performance costs.
We’ll need to download and install the mypy tool. Generally, this is done with the following terminal command:
(cookbook3) % python -m pip install mypy
Using the python -m pip command ensures the pip command will be associated with the currently active virtual environment. In this example, the prompt shows a virtual environment named cookbook3.
We can also use the pyright tool to examine type hints.
For an example of type hints, we’ll look at some color computations...