Using Mypy with SublimeText 3 Latest update: 18 March, 2018

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.

1. 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:

python3.6 -m pip install mypy

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:

sudo apt-get install python3.6-dev

Note: If installation is failing because of lack of permission, try to install mypy using the user’s home directory with the --user flag:

python3.6 -m pip install mypy --user

2. Installing Anaconda

The Anaconda plugin can be installed with the Package Control for SBT3 by simply searching for anaconda .

3. 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):

{ "python_interpreter" : "python3.6" , "anaconda_linting_behaviour" : "load-save" , "anaconda_linter_phantoms" : true , "mypy" : true , }

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_behaviour and make anaconda display the errors inline with anaconda_linter_phantoms .

and make anaconda display the errors inline with . activate mypy ;

All options along with their explanations can be found in Anaconda -> Settings-Default.

4. Using it

With everything setup properly we should be getting the type checks from mypy alongside other lint checks.

Please enable JavaScript to view the comments powered by Disqus.