Skip to content

chore: type annotations and numpy docstrings everywhere, enforced in lint; add AGENTS.md - #44

Merged
mpvginde merged 6 commits into
mlwp-tools:refactor/alignmentfrom
leifdenby:chore/annotations-docstrings
Oct 27, 2026
Merged

mpvginde merged 6 commits into
mlwp-tools:refactor/alignmentfrom
leifdenby:chore/annotations-docstrings

Conversation

@leifdenby

@leifdenby leifdenby commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Every function now has type annotations on all arguments and return values and a numpy-style docstring. A lint check keeps it that way, and AGENTS.md describes the project's coding conventions and development tools.

Note

This builds on #41 and #42, a stack of follow-ups to #30 (refactor/alignment). All of these come from my fork, and GitHub can't stack PRs across forks, so this one targets refactor/alignment (#30) and also shows their commits. Only the last commit is new here.

Enforcement (runs in pre-commit, and so in the existing lint CI)

  • pyproject.toml enables ruff's ANN rules (annotations) and D rules (docstrings, numpy convention), with no exemptions for tests.
  • The new numpydoc-validation hook (v1.11.0) checks that every parameter, return value and so on is documented. It runs all checks except EX01/SA01/ES01 (Examples, See Also and Extended Summary are optional). __init__ is excluded because the class docstring documents its parameters.
  • src/mxalign/loaders/ifs_forecast.py is excluded from both: it's orphaned and imports modules that no longer exist, and it should be removed or ported to mlwp-data-loaders separately.

Code (src/, tests/, examples/myloader.py)

  • Every module, class, function, method and test now has full annotations, with no Any; pass-through **kwargs are typed object. Each also has a numpy docstring (Parameters / Returns / Raises).
  • pydantic config models document their fields under Attributes, because numpydoc can't see pydantic's generated constructor.
  • No behaviour change. An AST comparison with docstrings, annotations and imports stripped shows only three code differences:
    • mxalign.__all__ is now sorted.
    • dict(...) became {...} in two tests.
  • All 100 tests pass.

AGENTS.md: package layout, development tools (uv, pytest, pre-commit), coding conventions (annotations, numpy docstrings with an example, no mutation of inputs, registries, config schema), tests, CHANGELOG and ADRs.

Possible bugs found while documenting, not fixed here (each could be its own issue):

  • Runner.verify: if verification.save is set but there are no metrics, self.metrics is never assigned, so saving raises AttributeError.
  • Runner.load_datasets: if none of a dataset's files exist, an empty list is passed to the loader.
  • DatasetPath: for a dataset that is neither forecast nor observation, year/month/day are never set, so substitute raises AttributeError.
  • MxAccessor.align_time_with: can pass a list/timedelta lead_time to align_forecast_to_forecast, which only accepts "reference"/"intersection"/"union".
  • utils/traits.update_*_trait: the validation report is discarded, so invalid traits are never reported.
  • broadcast_nans: an empty dict input comes back as an empty list.
  • The transformation name kelvin_to_celcius is misspelled (should be "celsius"), and it's public.

🤖 Generated with Claude Code

leifdenby and others added 5 commits October 27, 2026 15:33
The YAML-driven pipeline (cli, runner, verification, transformations
and the config/dates/save helpers it alone uses) now lives in
mxalign.pipeline. The console script points at mxalign.pipeline.cli:main.
Public re-exports from mxalign/__init__.py are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the untyped Config dict wrapper with pydantic models
(PipelineConfig and one model per section) loaded via load_config().
Unknown or missing keys now fail when the Runner is created instead of
deep inside a run, and the Runner reads typed attributes rather than
popping keys (which also stops align() mutating the config). Keys that
are forwarded to loaders, transformations, metrics and save methods
are kept as pass-through kwargs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…add AGENTS.md

Every module, class, function and method in src/, tests/ and the example
loader now has type annotations on all arguments and return values and a
numpy-style docstring (Parameters/Returns/Raises). This is enforced in
pre-commit (and therefore CI) by ruff's ANN and D rules (numpy convention)
and the numpydoc-validation hook. AGENTS.md describes the package layout,
development tools and coding conventions.

No behaviour changes: apart from docstrings, annotations and import
sorting, the only code edits are sorting mxalign.__all__ and dict literals
in tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leifdenby
leifdenby force-pushed the chore/annotations-docstrings branch from 676c850 to 228f76c Compare October 27, 2026 14:33
@mpvginde
mpvginde merged commit f5937a0 into mlwp-tools:refactor/alignment Oct 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants