In this article we’ll explore how to use mypy, a static-type checker for python, with the SublimeText 3 code editor(henceforth SBT3). We’ll need to install the mypy python package and a plugin for SBT3 called Anaconda. Anaconda adds various features to SBT3 like: code completion, linting, code analyzer, etc.
The end result will be type checks for our python code while we type or when saving/loading a file. Let’s get started.
Installing Mypy
Mypy can be easily installed with pip. We can use the pip module from our current python interpreter to ensure the package gets installed for our current python version, like so:
| |
Note: If the installation fails because of missing dependencies, you may need to install python-dev for the python version in use and then retry the instalation:
| |
Note: If installation is failing because of lack of permission, try to install mypy using the user’s home directory with the --user flag:
| |
Installing Anaconda
The Anaconda plugin can be installed with the Package Control for SBT3 by simply searching for anaconda.
Configuring Anaconda
Next up, we need to configure anaconda. We’ll add the following configs into anaconda’s user settings(Preferences -> Package Settings -> Anaconda -> Settings-User):
| |
Here we:
- set the python interpreter we want anaconda to use(this can be overridden on project basis);
- make anaconda process python code only when the file is loaded or saved with
anaconda_linting_behaviourand make anaconda display the errors inline withanaconda_linter_phantoms. - activate
mypy;
All options along with their explanations can be found in Anaconda -> Settings-Default.
Using it
With everything setup properly we should be getting the type checks from mypy alongside other lint checks.
