Skip to content

Mypy issues #3387

Description

@jaredclaypoole

Summary

  • Mypy, as currently configured, fails to run with poetry run mypy
  • The current mypy settings are hiding real typing issues in the repo
    • It would take time and effort to resolve all the mypy issues, but we'd certainly fix some real typing issues and possibly some algorithm issues

Details

  • When I refer to running mypy, I'm referring to poetry run mypy

  • The pinned version of mypy (v1.10.1) fails to run (with an internal error) on the current dev branch

    • Upgrading mypy (to the latest 1.x version, v1.20.2) resolves the issue
      • After upgrading, just one mypy error is reported with the current settings:

        imap_processing/spice/pointing_frame.py:270: error: Need type annotation for "pointing_segments" [var-annotated]

        Found 1 error in 1 file (checked 225 source files)

        • The error is kind of silly; apparently mypy doesn't know that np.zeros returns type np.ndarray.
          Other errors discussed below are more serious.
        • Same result with the latest stable version of mypy, v2.3.0
  • The mypy settings in pyproject.toml currently contain the line

    follow_imports = 'skip' #may want to remove

    Note the comment saying we may want to remove this!

    • Including this line introduces a few issues, such as hiding some real mypy errors.

    • Removing "follow_imports = 'skip'" and running mypy with the current mypy version (v1.10.1) yields many errors:

      Found 234 errors in 62 files (checked 225 source files)

      • A lot of these are issues like "expected ndarray; got DataArray" or similar,
        which expose mismatches between our declared APIs and their usage.
    • Removing this line and running mypy after the mypy upgrade (so using mypy v1.20.2) yields slightly fewer errors:

      Found 220 errors in 60 files (checked 225 source files)

      • Same results when running the latest stable version of mypy, v2.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions