Mypy and Continuous Integration sequence part 2: Continuous Integration

Quinn Dougherty
3 min readJul 14, 2019

In part one I showed how a simple program can be improved by type hints and introduced some concepts in type-centric programming. Today, I’ll show how to wire up the Mypy tool in your build process.

Continuous Integration: GitHub and Travis

Ok, with me now — go to Sign in with GitHub — signing up for Travis automatically links with your GH account.

You have to go to GitHub and enable Travis on the repositories you own.

Then, go to Settings on your Travis profile.

It should look like this

The `Settings` page in Travis-CI

Click Sync account on the left. This will scan your GitHub account for repositories.

Then, go into the filter and start typing the name of the repository you want to activate.

My repository is called mypy-ci-tutorial

Check the button so it slides to the right and turns blue, as seen.

Now it’s ready for a “build”.

The .travis.yml file

The build is configured in the .travis.yml file. Yaml is a simple configuration language that you should familiarize yourself with, as it shows up all over the place.

Let’s go back into our repository.

make a new file called .travis.yml.

We’ll look at it step by step

The first thing we need to do for Travis is declare what language we’re in.

Then, under the header python we declare versions.

On a lot of your projects, you can provide a list of versions, to cast a wide net. Today, since we used dataclasses for our Player class, we can only use 3.7.

Next we have the actual scripting

This says to cache with the pip package management tool so we can install mypy, the crux of the testing we’re going to run.

Finally, we run our actual tests with a call to mypy This will do the type-checking, and if any warnings are raised the entire “build” will fail.

If that’s what your .travis.yml file looks like, go ahead and git add .travis.yml, commit and push to github. Now watch your dashboard.

While it’s building, it shows in yellow. You can read the logs and see everything happen — it opens up a kind of virtual machine in the cloud, runs pip with the specified version of python, and makes it all the way down to your testing script. Everything should be familiar if you’re accustomed to reading terminal output during pip or other build processes.

If your build succeeds, you get green; if it fails, you get red, and try again!


You can automate testing of every push with continuous integration. Travis is an easy CI platform for all your github projects. Yaml is a simple configuration language that Travis uses to specify builds. Travis color codes builds; red for failed, yellow for in progress, and green for successful.

Join us in part 3 for a bonus round: Docker!