Skip to content

Stop using mypy's ignore_missing_imports option #225

@jtherrmann

Description

@jtherrmann

Our v0.14.0 reusable-mypy action runs the following mypy command:

mypy --install-types --ignore-missing-imports --non-interactive --pretty .

I observe some unexpected behavior with --ignore-missing-imports and --install-types. Using burst2safe as an example, if I checkout the latest develop commit, build the mamba environment and run the above command, it installs types-python-dateutil-2.9.0.20241206 and flags no issues.

However, if I remove .mypy_cache/ and re-build the environment, then run the above command without --ignore-missing-imports, it installs lxml-stubs-0.5.1 types-Pygments-2.19.0.20250107 types-colorama-0.4.15.20240311 types-docutils-0.21.0.20241128 types-python-dateutil-2.9.0.20241206 types-setuptools-75.8.0.20250110 and then flags 200 errors in 28 files.

Some of these errors do not seem directly related to missing imports, e.g. src/burst2safe/safe.py:338: error: Cannot determine type of "size_bytes" for L338, or even if it is, that's not an error that we would want to ignore. I thought that particular error might be related to importing Kml via from burst2safe.manifest import Kml, Manifest, Preview at L14 because perhaps mypy does not recognize the burst2safe package, but installing the package via pip install -e . or using a relative import for that line both did not change the number of errors reported, so I'm not sure what's going on there.

Also, if I run the mypy command with only --ignore-missing-imports, then the only error it flags is:

src/burst2safe/burst_id.py:11: error: Library stubs not installed for "dateutil"  [import-untyped]

which I suppose makes some sense since that's the library for which stubs are installed when I run the full mypy command, though I'm not sure why --ignore-missing-imports doesn't suppress that particular import.

So, my main concerns are:

  • Why does using --ignore-missing-imports prevent installation of stubs for all libraries (other than dateutil)? I think we want to install as many stubs as possible.
  • Some of the ignored errors are not errors that we should be ignoring.

I think that the ideal resolution to this issue would be to:

  1. Remove --ignore-missing-imports from our reusable action, and avoid enabling it in pyproject.toml for new projects (will need to be added to pyproject.toml for existing projects where removing it would cause many errors).
  2. Gradually remove it from pyproject.toml for existing projects as time allows.
  3. Going forward, use more granular methods of ignoring specific imports as needed. See Missing imports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Jira BugCreate a Jira Bug for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions