From e1733f37d033e99e010264d9793da534c10a21e6 Mon Sep 17 00:00:00 2001 From: Luke Conibear Date: Sun, 28 Aug 2022 21:57:03 +0100 Subject: [PATCH 01/10] fixed mypy type errors --- xarray/backends/api.py | 3 ++- xarray/core/merge.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/xarray/backends/api.py b/xarray/backends/api.py index ca040306bf0..89b882240dd 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -8,6 +8,7 @@ TYPE_CHECKING, Any, Callable, + Dict, Final, Hashable, Iterable, @@ -59,7 +60,7 @@ str, # no nice typing support for custom backends None, ] - T_Chunks = Union[int, dict[Any, Any], Literal["auto"], None] + T_Chunks = Union[int, Dict[Any, Any], Literal["auto"], None] T_NetcdfTypes = Literal[ "NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", "NETCDF3_CLASSIC" ] diff --git a/xarray/core/merge.py b/xarray/core/merge.py index 6262e031a2c..ca5ac3e71c6 100644 --- a/xarray/core/merge.py +++ b/xarray/core/merge.py @@ -40,9 +40,9 @@ ArrayLike = Any VariableLike = Union[ ArrayLike, - tuple[DimsLike, ArrayLike], - tuple[DimsLike, ArrayLike, Mapping], - tuple[DimsLike, ArrayLike, Mapping, Mapping], + Tuple[DimsLike, ArrayLike], + Tuple[DimsLike, ArrayLike, Mapping], + Tuple[DimsLike, ArrayLike, Mapping, Mapping], ] XarrayValue = Union[DataArray, Variable, VariableLike] DatasetLike = Union[Dataset, Mapping[Any, XarrayValue]] From 1dbae6c4884386b2668ac4638fc100732bffacf6 Mon Sep 17 00:00:00 2001 From: Michael Niklas Date: Thu, 13 Oct 2022 19:08:46 +0200 Subject: [PATCH 02/10] add mypy with python3.8 to ci --- .github/workflows/ci-additional.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index 7087b43abc3..62d2e6f4cc5 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -120,6 +120,10 @@ jobs: run: | python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report + - name: Run mypy with python3.8 + run: | + python -m mypy --install-types --non-interactive --python-version 3.8 + - name: Upload mypy coverage to Codecov uses: codecov/codecov-action@v3.1.1 with: From afdb930f9eff978fdbe2e8443e91d4714a5d8971 Mon Sep 17 00:00:00 2001 From: Michael Niklas Date: Thu, 13 Oct 2022 19:12:06 +0200 Subject: [PATCH 03/10] fix mypy python 3.8 problems --- xarray/core/types.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xarray/core/types.py b/xarray/core/types.py index 5ba6a53f2ef..24be1052876 100644 --- a/xarray/core/types.py +++ b/xarray/core/types.py @@ -6,10 +6,12 @@ Callable, Hashable, Iterable, + List, Literal, Protocol, Sequence, SupportsIndex, + Tuple, TypeVar, Union, ) @@ -69,13 +71,13 @@ def dtype(self) -> np.dtype: # character codes, type strings or comma-separated fields, e.g., 'float64' str, # (flexible_dtype, itemsize) - tuple[_DTypeLikeNested, int], + Tuple[_DTypeLikeNested, int], # (fixed_dtype, shape) - tuple[_DTypeLikeNested, _ShapeLike], + Tuple[_DTypeLikeNested, _ShapeLike], # (base_dtype, new_dtype) - tuple[_DTypeLikeNested, _DTypeLikeNested], + Tuple[_DTypeLikeNested, _DTypeLikeNested], # because numpy does the same? - list[Any], + List[Any], # anything with a dtype attribute _SupportsDType, ] From 6674f93c4376b6b587835c240dc2bfe53b1c3328 Mon Sep 17 00:00:00 2001 From: Michael Niklas Date: Thu, 13 Oct 2022 19:20:35 +0200 Subject: [PATCH 04/10] add verbosity flag to mypy action --- .github/workflows/ci-additional.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index 62d2e6f4cc5..9f61f8b95c0 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -118,11 +118,11 @@ jobs: - name: Run mypy run: | - python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report + python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report -v - name: Run mypy with python3.8 run: | - python -m mypy --install-types --non-interactive --python-version 3.8 + python -m mypy --install-types --non-interactive --python-version 3.8 -v - name: Upload mypy coverage to Codecov uses: codecov/codecov-action@v3.1.1 From 7018b9509dfb78f0ae8530e45ebd861018b0f06b Mon Sep 17 00:00:00 2001 From: Michael Niklas Date: Thu, 13 Oct 2022 19:32:06 +0200 Subject: [PATCH 05/10] silence import errors in mypy python 3.8 --- .github/workflows/ci-additional.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index 9f61f8b95c0..e5dc71d28c7 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -121,8 +121,9 @@ jobs: python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report -v - name: Run mypy with python3.8 + # silent all imports, since external repos might not support this run: | - python -m mypy --install-types --non-interactive --python-version 3.8 -v + python -m mypy --install-types --non-interactive --python-version 3.8 -v --follow-imports=silent - name: Upload mypy coverage to Codecov uses: codecov/codecov-action@v3.1.1 From 69692a62159f75a879d39122d3c00a6cd083e371 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 20 Nov 2022 19:37:10 +0100 Subject: [PATCH 06/10] Test copying the entire workflow. --- .github/workflows/ci-additional.yaml | 58 ++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index a1660afd22e..fe3cadfdb1c 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -125,10 +125,10 @@ jobs: run: | python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report -v - - name: Run mypy with python3.8 - # silent all imports, since external repos might not support this - run: | - python -m mypy --install-types --non-interactive --python-version 3.8 -v --follow-imports=silent + # - name: Run mypy with python3.8 + # # silent all imports, since external repos might not support this + # run: | + # python -m mypy --install-types --non-interactive --python-version 3.8 -v --follow-imports=silent - name: Upload mypy coverage to Codecov uses: codecov/codecov-action@v3.1.1 @@ -139,6 +139,56 @@ jobs: name: codecov-umbrella fail_ci_if_error: false + mypy38: + name: Mypy 3.8 + runs-on: "ubuntu-latest" + needs: detect-ci-trigger + # temporarily skipping due to https://github.com/pydata/xarray/issues/6551 + if: needs.detect-ci-trigger.outputs.triggered == 'false' + defaults: + run: + shell: bash -l {0} + env: + CONDA_ENV_FILE: ci/requirements/environment.yml + PYTHON_VERSION: "3.8" + + steps: + - uses: actions/checkout@v3 + 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/provision-with-micromamba@v14 + with: + environment-file: ${{env.CONDA_ENV_FILE}} + environment-name: xarray-tests + extra-specs: | + python=${{env.PYTHON_VERSION}} + conda + cache-env: true + cache-env-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: | + conda info -a + conda list + python xarray/util/print_versions.py + - name: Install mypy + run: | + python -m pip install 'mypy<0.990' + + - name: Run mypy + run: | + python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report -v + + + + min-version-policy: name: Minimum Version Policy runs-on: "ubuntu-latest" From 88e6f7c121a81bcb38ab8dc579ad9db830c6a1e1 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 20 Nov 2022 19:46:50 +0100 Subject: [PATCH 07/10] Update ci-additional.yaml --- .github/workflows/ci-additional.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index fe3cadfdb1c..5a6fd5fc506 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -123,7 +123,7 @@ jobs: - name: Run mypy run: | - python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report -v + python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report # - name: Run mypy with python3.8 # # silent all imports, since external repos might not support this @@ -184,7 +184,7 @@ jobs: - name: Run mypy run: | - python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report -v + python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report From d845fecd80ecb320f2de70f295869a62c171e428 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:41:37 +0100 Subject: [PATCH 08/10] Last test running 3.8 inside mypy workflow --- .github/workflows/ci-additional.yaml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index 5a6fd5fc506..4bea674b080 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -125,10 +125,10 @@ jobs: run: | python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report - # - name: Run mypy with python3.8 - # # silent all imports, since external repos might not support this - # run: | - # python -m mypy --install-types --non-interactive --python-version 3.8 -v --follow-imports=silent + - name: Run mypy with python3.8 + # silent all imports, since external repos might not support this + run: | + python -m mypy --install-types --non-interactive --python-version 3.8 --follow-imports=silent - name: Upload mypy coverage to Codecov uses: codecov/codecov-action@v3.1.1 @@ -186,6 +186,14 @@ jobs: run: | python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report + - name: Upload mypy coverage to Codecov + uses: codecov/codecov-action@v3.1.1 + with: + file: mypy_report/cobertura.xml + flags: mypy + env_vars: PYTHON_VERSION + name: codecov-umbrella + fail_ci_if_error: false From aabbf7f8ad4d2d7295213b8c191e5a438d101858 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:56:34 +0100 Subject: [PATCH 09/10] Update ci-additional.yaml --- .github/workflows/ci-additional.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index 4bea674b080..c7138877ade 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -190,7 +190,7 @@ jobs: uses: codecov/codecov-action@v3.1.1 with: file: mypy_report/cobertura.xml - flags: mypy + flags: mypy38 env_vars: PYTHON_VERSION name: codecov-umbrella fail_ci_if_error: false From 27cdc3326f93b2ac1cf10dbdff6cdbac4a44284d Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 20 Nov 2022 21:05:59 +0100 Subject: [PATCH 10/10] Use the copy/pasted workflow only --- .github/workflows/ci-additional.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index c7138877ade..bdae56ae6db 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -125,11 +125,6 @@ jobs: run: | python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report - - name: Run mypy with python3.8 - # silent all imports, since external repos might not support this - run: | - python -m mypy --install-types --non-interactive --python-version 3.8 --follow-imports=silent - - name: Upload mypy coverage to Codecov uses: codecov/codecov-action@v3.1.1 with: