Skip to content

[Maintenance] Enforce 100% type-hint coverage and align typing to PEP 585/604 #670

Description

@sadamov

We have been adding type hints module-by-module through a long series of issues
(#617, #619, #621, #624, #630, #646, #446, #454, and the four currently in flight:
#662 / #664 / #666 / #668). That piecemeal approach got us most of the way, time to complete the journey :)

1. Reach 100% annotation coverage. Every function and method in neural_lam/ gets full
parameter and return annotations. mypy --disallow-untyped-defs --disallow-incomplete-defs
currently flags 43 gaps across 15 files (run it for the live list):

12  models/module.py
 6  datastore/npyfilesmeps/compute_standardization_stats.py
 4  datastore/npyfilesmeps/store.py
 3  train_model.py
 3  models/step_predictors/graph/hi_lam.py
 2  weather_dataset.py
 2  models/step_predictors/graph/hierarchical.py
 2  models/step_predictors/graph/base.py        # fixed by #667
 2  models/step_predictors/base.py              # fixed by #665
 2  datastore/plot_example.py
 1  vis.py
 1  utils.py
 1  models/step_predictors/graph/hi_lam_parallel.py
 1  models/step_predictors/graph/graph_lam.py   # fixed by #669
 1  datastore/__init__.py

2. Align to modern conventions (PEP 585 / 604). Repo-wide rewrite:

  • Optional[X] -> X | None
  • Union[A, B] -> A | B
  • Dict / List / Tuple -> dict / list / tuple
  • drop the now-unused from typing import Dict, List, Tuple, Union, Optional imports

This is mechanical and can be auto-applied with pyupgrade --py310-plus (or ruff UP rules
if #614 lands first); review the diff afterwards.

3. Enforce going forward. Add a [tool.mypy] block and turn on the coverage gate so an
untyped def fails pre-commit/CI, the type analog of interrogate:

[tool.mypy]
python_version = "3.10"
disallow_untyped_defs = true
disallow_incomplete_defs = true

Note:

  • Tests and docs dirs stay out of scope, consistent with the interrogate exclude list.

Metadata

Metadata

Assignees

Labels

maintenanceRefactoring codebase, no new behaviour

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions