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
- 'make typecheck' fails with "error: Can't find package 'PACKAGE_NAME'" despite package existing in workspace
- Mypy errors occur after creating a new package in packages/ directory
- Inspecting mypy configuration shows mypy_path is missing the new package's src directory
Pattern
- Create new package in packages/PACKAGE_NAME/
- Open pyproject.toml or mypy.ini configuration file
- Locate the mypy_path setting
- Add 'packages/PACKAGE_NAME/src' to the mypy_path list
- 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
- Type checking works: mypy finds all workspace packages
- CI passes: No false positives from missing packages
- Complete coverage: All packages included in type checks
Related
- Configure pytest pythonpath - Similar pytest configuration