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.

Adding this Github Actions workflow will run these checks when a pull request is created, catching problems before they’re merged.

How to add the Github Actions workflow

Add the following to your repository in .github/workflows/code-quality.yml.

name: Checks
on: [pull_request]

    runs-on: ubuntu-latest
    name: Checks
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
        python-version: 3.x
    - run: pip install --upgrade pip
    - run: pip install black==21.6b0 pylint==v3.0.0a3 mypy==v0.902
    - run: black --diff --check $(git ls-files '*.py')
    - run: pylint --disable=all --enable=unused-import $(git ls-files '*.py')
    - run: mypy --strict $(git ls-files '*.py')


See also: How to use Black, Pylint and Mypy in Pre-commit?