Skip to content

fix: enable proper mypy checking for idc_index_data_manager.py #143

Description

@fedorov

Background

scripts/python/idc_index_data_manager.py is currently excluded from mypy checking via a # mypy: ignore-errors directive added as a workaround (commit f38ef02).

Problem

The file has a deferred google.cloud.storage import inside a function body:

if gcs_cache_bucket ...:
    from google.cloud import storage  # noqa: PLC0415

This causes a persistent conflict between ruff and mypy:

  1. from google.cloud import storage → mypy raises [attr-defined] (google-cloud-storage not in mypy's pre-commit env stubs)
  2. import google.cloud.storage as storage → mypy raises [import-untyped], but ruff's PLC0415 auto-fix converts it back to from google.cloud import storage
  3. Any # type: ignore[...] comment gets relocated by ruff's auto-formatter, breaking mypy suppression
  4. # fmt: off / # ruff: disable blocks are ignored by ruff-check's --fix mode

Fix options to investigate

  • Add proper type stubs for google-cloud-storage to the mypy pre-commit environment that correctly integrate with the google.cloud namespace package (the google-cloud-bigquery stubs may be shadowing google.cloud.storage)
  • Add a [[tool.mypy.overrides]] in pyproject.toml scoped to scripts.python.idc_index_data_manager with disable_error_codes = ["attr-defined", "import-untyped"]
  • Restructure the import to avoid the ruff/mypy conflict (e.g., use importlib.import_module)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions