What problem does this solve?
The LandmarkDiff repository currently has incomplete type annotations that prevent comprehensive mypy type checking. This creates several problems:
-
No type safety in scripts and benchmarks – The CI only runs mypy landmarkdiff/, leaving 125+ scripts and 3 benchmarks completely unchecked.
-
Errors are silently ignored – Most modules in pyproject.toml have ignore_errors = true, which means mypy runs but doesn't report actual type errors.
-
Pre-commit mypy hook is disabled – Due to duplicate module issues and type annotation gaps, mypy cannot run cleanly in pre-commit.
-
No real type checking happens – Despite mypy being configured, the combination of ignore_errors = true and limited scope means type errors go undetected.
Goal: Enable meaningful, comprehensive mypy type checking across the entire codebase to catch type-related bugs early and improve code quality.
Proposed solution
Phase 1: Configuration Updates
Update pyproject.toml mypy settings:
[tool.mypy]
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
check_untyped_defs = true
explicit_package_bases = true
ignore_missing_imports = true
strict_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
-
Update CI to use parallel matrix for type checking:
landmarkdiff/ (main package)
scripts/ (all scripts)
benchmarks/ (benchmark scripts)
-
Enable mypy in pre-commit with --explicit-package-bases flag to handle duplicate module names without file renames.
-
Add package __init__.py files to directories that need them.
Phase 2: Remove ignore_errors = true (Module by Module)
The current pyproject.toml has ignore_errors = true for 33 modules. This will be removed incrementally:
- Start with simpler modules (e.g.,
api_client, config, log)
- Run mypy to identify type errors
- Add missing type annotations
- Verify module passes mypy
- Move to next module
Example fix:
# Before
def process_image(img, size):
return cv2.resize(img, (size, size))
# After
def process_image(img: np.ndarray, size: int) -> np.ndarray:
return cv2.resize(img, (size, size))
Phase 3: Scripts Type Annotations
After landmarkdiff is complete:
- Run mypy on
scripts/ directory
- Add type annotations to all functions
- Fix any type errors
Phase 4: Benchmarks Type Annotations
Apply the same process to benchmarks/ directory.
Alternatives considered
No response
Area of the project
CLI / scripts
Would you be willing to implement this?
Yes, I'd like to submit a PR
References
#405 , #396
What problem does this solve?
The LandmarkDiff repository currently has incomplete type annotations that prevent comprehensive mypy type checking. This creates several problems:
No type safety in scripts and benchmarks – The CI only runs
mypy landmarkdiff/, leaving 125+ scripts and 3 benchmarks completely unchecked.Errors are silently ignored – Most modules in
pyproject.tomlhaveignore_errors = true, which means mypy runs but doesn't report actual type errors.Pre-commit mypy hook is disabled – Due to duplicate module issues and type annotation gaps, mypy cannot run cleanly in pre-commit.
No real type checking happens – Despite mypy being configured, the combination of
ignore_errors = trueand limited scope means type errors go undetected.Goal: Enable meaningful, comprehensive mypy type checking across the entire codebase to catch type-related bugs early and improve code quality.
Proposed solution
Phase 1: Configuration Updates
Update
pyproject.tomlmypy settings:Update CI to use parallel matrix for type checking:
landmarkdiff/(main package)scripts/(all scripts)benchmarks/(benchmark scripts)Enable mypy in pre-commit with
--explicit-package-basesflag to handle duplicate module names without file renames.Add package
__init__.pyfiles to directories that need them.Phase 2: Remove
ignore_errors = true(Module by Module)The current
pyproject.tomlhasignore_errors = truefor 33 modules. This will be removed incrementally:api_client,config,log)Example fix:
Phase 3: Scripts Type Annotations
After
landmarkdiffis complete:scripts/directoryPhase 4: Benchmarks Type Annotations
Apply the same process to
benchmarks/directory.Alternatives considered
No response
Area of the project
CLI / scripts
Would you be willing to implement this?
Yes, I'd like to submit a PR
References
#405 , #396