Black, Isort, and Mypy logos

Black

Isort

  • Isort specializes in sorting and organizing import statements in Python files. It sorts imports alphabetically, groups them into sections (e.g., standard library, third-party, local imports), and formats multi-line imports for readability. Isort can also add or remove imports automatically as configured.
  • Like Black, it can be integrated into workflows: isort --check-only .
  • Here’s their repo: https://github.com/pycqa/isort/
  • I am using the extension https://marketplace.visualstudio.com/items?itemName=ms-python.isort.
  • Once installed: command palette > Organize imports.

Mypy

Mypy setting in VSCode

  • Here’s an example of what this tool can do for us: it warns us as we’re writing code that a None cannot be added to a dict:

Mypy in action

  • But what if I did not specify the type? Then I’d have to run mypy in strict mode to catch the errors. That can be specified in the pyproject.toml, which takes us to my next point where I answer this.

Configuring dev tools in the pyproject.toml

Mypy in action

  • To fix it, we’d have do something like this:

Mypy in action

  • To install our dependencies the command stays the same. But to install the optional dependencies:
    pip install .[dev]
    

    This installs the main dependencies and the dev tools.

  • VSCode reads the [tool.*] configs in our pyproject.toml automatically. So we’re set in our local development environment. But what about the CI?

GHA for Code Quality Checks in CI