Skip to content

WIP: Harden types#45

Open
mcocdawc wants to merge 5 commits intodevelopfrom
harden_types
Open

WIP: Harden types#45
mcocdawc wants to merge 5 commits intodevelopfrom
harden_types

Conversation

@mcocdawc
Copy link
Copy Markdown
Contributor

Description

As a followup on #43 the type checking is hardened a bit.

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens static typing support across earthkit-climate as a follow-up to #43, adding mypy configuration, improving type annotations, and marking the package as PEP 561 typed.

Changes:

  • Add PEP 561 py.typed marker (and packaging + test coverage for it).
  • Introduce/strengthen typing via TypeAlias and Protocol in core conversion/wrapper/provenance utilities.
  • Configure mypy in pyproject.toml and update the pixi task to run mypy against src and tests.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_00_version.py Switch import style and add a test asserting py.typed presence.
src/earthkit/climate/utils/provenance.py Add a Protocol for indicator typing and tighten the add_indicator_provenance signature.
src/earthkit/climate/utils/conversions.py Replace legacy typing constructs with TypeAlias, built-in generics, and collections.abc.
src/earthkit/climate/py.typed Add PEP 561 marker file.
src/earthkit/climate/indicators/init.py Export indicator submodules via explicit imports and __all__.
src/earthkit/climate/api/wrapper.py Add Protocol/type aliases for wrapped xclim indicators and improve annotations.
src/earthkit/climate/init.py Normalize imports and fix __all__ to use string exports.
pyproject.toml Add mypy config, include py.typed as package data, and add pandas-stubs to dev deps.
pixi.toml Add pandas-stubs for dev and update the type-check task.
.pre-commit-config.yaml Remove redundant ruff line-length arg (now configured in pyproject.toml).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.



def test_py_typed_marker_present() -> None:
assert Path(climate.__file__).with_name("py.typed").is_file()
Comment on lines +21 to +24
class IndicatorWithCompute(Protocol):
"""Indicator-like object with a callable interface and a compute method."""

def compute(self, *args: Any, **kwargs: Any) -> object: ...
Comment on lines +32 to 35
def wrap_xclim_indicator(xclim_fn: XclimIndicator) -> Callable[..., conversions.EarthkitData]:
"""
Wraps an xclim indicator to handle Earthkit inputs and unit alignment.

Comment on lines +16 to +19
import earthkit.climate.indicators.precipitation as precipitation
import earthkit.climate.indicators.temperature as temperature

__all__ = ["precipitation", "temperature"]
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