Use black, mypy, and pylint to make your Python code more professional

Let’s write our Python code like a Pro

Lynn G. Kwong
9 min readDec 8, 2021

When you write Python code by yourself, you may not pay attention to the styling. As long as the code works, you may say “job is done”. Well, if you never share your code with anyone else, it’s OK. However, it’s not OK if you work in a team, and not OK at all if you are a professional Python developer. Good styling, type annotation, and documentation can make your Python code more professional, more readable, and also more enjoyable for others.

If you are planning to become a professional Python developer, you will find this post very helpful one day because when you share your code with your future employers, high-quality Python code will give you a major bonus in your interviews.

Photo by Hunters Race on Unsplash

In this post, I will introduce how to use black, mypy, and pylint to check the styling and type annotation of your Python code. We will first introduce the standalone command-line usage and then introduce how to configure them in VS code. Documentation with docstrings is rather subjective and is difficult to check automatically. However, pylint and pydocstyle can still be used to check the general format of the docstrings.

Use black for code formatting

--

--

Lynn G. Kwong

I’m a Software Developer (https://youtube.com/@kwonglynn) keen on sharing thoughts, tutorials, and solutions for the best practice of software development.