Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime type checking in CI tests #9745

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/ci-additional.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions ci/requirements/environment.yml
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ dependencies:
- pydap
- pydap-server
- pytest
- pytest-beartype
- pytest-cov
- pytest-env
- pytest-xdist
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ dev = [
"mypy",
"pre-commit",
"pytest",
"pytest-beartype",
"pytest-cov",
"pytest-env",
"pytest-xdist",
@@ -290,6 +291,9 @@ ban-relative-imports = "all"
[tool.pytest.ini_options]
addopts = ["--strict-config", "--strict-markers"]

[lint.pyupgrade]
keep-runtime-typing = true

# We want to forbid warnings from within xarray in our tests — instead we should
# fix our own code, or mark the test itself as expecting a warning. So this:
# - Converts any warning from xarray into an error
4 changes: 2 additions & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
@@ -468,7 +468,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):
@@ -550,7 +550,7 @@ class Dataset(
DataWithCoords,
DatasetAggregations,
DatasetArithmetic,
Mapping[Hashable, "DataArray"],
Mapping[Hashable, "xarray.DataArray"],
):
"""A multi-dimensional, in memory, array database.