From 2aaf0371d438adc96584eaecbaa67c8494828009 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:12:31 +0100 Subject: [PATCH 1/2] Add runtime type checking in CI tests This should prevent TYPE_CHECKING misuse. It might also found issues not found by static type checking, typically by the current MyPy. Make it optional for now, while we fix issues. --- .github/workflows/ci-additional.yaml | 41 ++++++++++++++++++++++++++++ ci/requirements/environment.yml | 1 + pyproject.toml | 1 + 3 files changed, 43 insertions(+) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index 9ef315f505c..fa29ec844af 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -80,6 +80,47 @@ jobs: # `xarray/tests/__init__.py`. python -m pytest --doctest-modules xarray --ignore xarray/tests -Werror + beartype: + name: beartype + runs-on: "ubuntu-latest" + needs: detect-ci-trigger + defaults: + run: + shell: bash -l {0} + env: + CONDA_ENV_FILE: ci/requirements/environment.yml + PYTHON_VERSION: "3.12" + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for all branches and tags. + + - name: set environment variables + run: | + echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV + - name: Setup micromamba + uses: mamba-org/setup-micromamba@v2 + with: + micromamba-version: ${{env.MICROMAMBA_VERSION}} + environment-file: ${{env.CONDA_ENV_FILE}} + environment-name: xarray-tests + create-args: >- + python=${{env.PYTHON_VERSION}} + cache-environment: true + cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}" + - name: Install xarray + run: | + python -m pip install --no-deps -e . + - name: Version info + run: | + python xarray/util/print_versions.py + + - name: Run beartype + continue-on-error: true + run: | + python -m pytest --beartype-packages=xarray + mypy: name: Mypy runs-on: "ubuntu-latest" diff --git a/ci/requirements/environment.yml b/ci/requirements/environment.yml index c630bce2ac8..161529d0569 100644 --- a/ci/requirements/environment.yml +++ b/ci/requirements/environment.yml @@ -38,6 +38,7 @@ dependencies: - pydap - pydap-server - pytest + - pytest-beartype - pytest-cov - pytest-env - pytest-xdist diff --git a/pyproject.toml b/pyproject.toml index 55c8d92bfdb..1166b3b0998 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ dev = [ "mypy", "pre-commit", "pytest", + "pytest-beartype", "pytest-cov", "pytest-env", "pytest-xdist", From 02104f2c86946fe213ebcb059d17128acb2e580e Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 10 Nov 2024 14:39:27 +0100 Subject: [PATCH 2/2] TESTING --- xarray/core/dataset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index a09a857e331..3f809087f82 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -441,7 +441,7 @@ def merge_data_and_coords(data_vars: DataVars, coords) -> _MergeResult: ) -class DataVariables(Mapping[Any, "DataArray"]): +class DataVariables(Mapping[Any, "xarray.DataArray"]): __slots__ = ("_dataset",) def __init__(self, dataset: Dataset): @@ -523,7 +523,7 @@ class Dataset( DataWithCoords, DatasetAggregations, DatasetArithmetic, - Mapping[Hashable, "DataArray"], + Mapping[Hashable, "xarray.DataArray"], ): """A multi-dimensional, in memory, array database.