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:
from google.cloud import storage → mypy raises [attr-defined] (google-cloud-storage not in mypy's pre-commit env stubs)
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
- Any
# type: ignore[...] comment gets relocated by ruff's auto-formatter, breaking mypy suppression
# 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)
Background
scripts/python/idc_index_data_manager.pyis currently excluded from mypy checking via a# mypy: ignore-errorsdirective added as a workaround (commit f38ef02).Problem
The file has a deferred
google.cloud.storageimport inside a function body:This causes a persistent conflict between ruff and mypy:
from google.cloud import storage→ mypy raises[attr-defined](google-cloud-storage not in mypy's pre-commit env stubs)import google.cloud.storage as storage→ mypy raises[import-untyped], but ruff's PLC0415 auto-fix converts it back tofrom google.cloud import storage# type: ignore[...]comment gets relocated by ruff's auto-formatter, breaking mypy suppression# fmt: off/# ruff: disableblocks are ignored by ruff-check's--fixmodeFix options to investigate
google-cloud-storageto the mypy pre-commit environment that correctly integrate with thegoogle.cloudnamespace package (thegoogle-cloud-bigquerystubs may be shadowinggoogle.cloud.storage)[[tool.mypy.overrides]]inpyproject.tomlscoped toscripts.python.idc_index_data_managerwithdisable_error_codes = ["attr-defined", "import-untyped"]importlib.import_module)