Python’s not the strictest language, so to have any confidence in your code you need to hit it with a barrage of checks to ensure it meets at least some level of quality.

The tools I use are Black to ensure code is formatted, Pylint to disallow unused imports, and Mypy for type checking.

Installing these Pre-commit hooks will run these checks locally when you try to commit, catching problems before they reach your repository.

How to install the Pre-commit hooks

Install Pre-commit.

Add the following .pre-commit-config.yaml file to the root of your repository.

fail_fast: true

  - repo:
    rev: 21.6b0
      - id: black
        args: [--diff, --check]

  - repo:
    rev: v3.0.0a3
      - id: pylint
        args: [--disable=all, --enable=unused-import]

  - repo:
    rev: v0.902
      - id: mypy
        exclude: ^tests/
        args: [--strict]

Install them as git hooks:

pre-commit install


Recommended: How to use Black, Pylint and Mypy in Github Actions?