Skip to content

Fix Mypy Static Type Checking Errors in Export Modules #158

Description

@omen18

Bug Report: Mypy Static Type Checking Errors in Export Modules

Description

When running mypy python/src on the coreai-models Python package, several static type checking errors occur due to variable scoping/shadowing and type annotations in model export modules:

  1. Union type ambiguity in segmentation/export.py:
    The config variable is assigned a FullExportConfig instance in the if args.full: branch and a SegmentationExportConfig instance in the else: branch. Consequently, static type checkers evaluate config as a union (FullExportConfig | SegmentationExportConfig), causing type errors when accessing fields unique to SegmentationExportConfig (such as max_text_seq_len, image_n_bits, image_group_size, text_n_bits, text_group_size).

  2. ExportConfig variant literal assignment in llm/export.py:
    The variant string parsed from command-line arguments is passed to ExportConfig(...), which expects Literal['macOS', 'iOS'], causing an arg-type mismatch.

  3. Variable name shadowing in vlm/export.py:
    The spec variable used in the --list-models iteration loop (for name, spec in SUPPORTED_MODELS.items():) shadows the lookup result of spec = SUPPORTED_MODELS.get(args.model) later in main().

Steps to Reproduce

  1. In the repository root, install dependencies with uv sync.
  2. Run uv run mypy python/src.
  3. Observe the reported type errors.

Expected Behavior

mypy python/src should evaluate exported CLI tools and pipeline modules with zero static type errors.

Suggested Fix

  • Disambiguate config -> seg_config in segmentation/export.py.
  • Explicitly cast/narrow variant to Literal["macOS", "iOS"] in llm/export.py.
  • Rename loop variable in vlm/export.py from spec to target_spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions