Skip to content

feat: Add mypy CI job and enforce stricter type checking

Mohana Sri Bhavitha requested to merge gitlab.ci/bhavitha into feature-final

Overview

Added mypy type checking as a CI job and enabled stricter type checking configuration to catch potential type errors at lint time.

Changes

CI Integration

  • .gitlab-ci.yml: Added mypy job in test stage
    • Runs uv run mypy on all backend code directories
    • Reuses existing before_script for dependency setup (no duplication)
    • Same trigger rules as other jobs (MRs, default branch, feature-final)

Configuration

  • mypy.ini: Updated with stricter settings
    • warn_return_any = True - Warn when returning Any from typed functions
    • strict_optional = True - Handle Optional types more strictly
    • no_implicit_optional = True - Require explicit Optional for nullable params
    • warn_redundant_casts = True - Catch unnecessary type casts
    • warn_unused_ignores = True - Keep ignore comments clean
    • show_error_codes = True - Display error codes for better debugging
    • pretty = True - Formatted error output
    • Excluded tests/* from type checking

Bug Fix

  • gitlab_utils/files_reader.py: Fixed type error
    • Added isinstance(content, bytes) check before decode
    • Returns proper str type instead of Any

Testing

Check Status
ruff check . Passed
mypy . Passed (87 source files)

Behavior

  • Pipeline: mypy now runs automatically on every push and MR
  • Failure: CI fails if type errors are present
  • Success: CI passes when all type checks pass
  • No breaking changes: Existing pipeline behavior preserved

Merge request reports

Loading