Add New Package Paths to mypy Configuration

lesson tools active tools/add-new-package-paths-to-mypy-.md View on GitHub

Add New Package Paths to mypy Configuration

Rule

When creating a new workspace package, immediately add 'packages/PACKAGE_NAME/src' to the mypy_path setting in mypy.ini (or pyproject.toml) to ensure mypy can locate the package for type checking.

Context

Mypy requires explicit source paths in its configuration to discover packages, even when those packages are properly installed in the workspace. Without the correct mypy_path entries, type checking will fail with 'Can't find package' errors despite the package being present and functional.

Detection

Pattern

  1. Create new package in packages/PACKAGE_NAME/
  2. Open pyproject.toml or mypy.ini configuration file
  3. Locate the mypy_path setting
  4. Add 'packages/PACKAGE_NAME/src' to the mypy_path list
  5. Run 'make typecheck' to verify mypy can now find the package
# In pyproject.toml
[tool.mypy]
mypy_path = "packages/package-a/src,packages/package-b/src,packages/NEW_PACKAGE/src"

Outcome

Related

Match Keywords

mypy Can't find package error new workspace package mypy failure mypy_path missing new package type checking fails after adding package add package to mypy.ini