python

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

repos:
  - repo: https://github.com/ambv/black
    rev: 21.6b0
    hooks:
      - id: black
        args: [--diff, --check]

  - repo: https://github.com/pre-commit/mirrors-pylint
    rev: v3.0.0a3
    hooks:
      - id: pylint
        args: [--disable=all, --enable=unused-import]

  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.902
    hooks:
      - id: mypy
        exclude: ^tests/
        args: [--strict]

Install them as git hooks:

pre-commit install

Notes

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