diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index dd18aa365d5..bdae56ae6db 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -134,6 +134,64 @@ 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 + + - name: Upload mypy coverage to Codecov + uses: codecov/codecov-action@v3.1.1 + with: + file: mypy_report/cobertura.xml + flags: mypy38 + env_vars: PYTHON_VERSION + name: codecov-umbrella + fail_ci_if_error: false + + + min-version-policy: name: Minimum Version Policy runs-on: "ubuntu-latest" diff --git a/xarray/backends/api.py b/xarray/backends/api.py index 302d0c350ef..a186bdf56d6 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -9,6 +9,7 @@ TYPE_CHECKING, Any, Callable, + Dict, Final, Hashable, Iterable, @@ -62,7 +63,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 f01f503f90d..859b3aeff8f 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]] diff --git a/xarray/core/types.py b/xarray/core/types.py index 2b65f4d23e6..884ea0b59ee 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, ) @@ -70,13 +72,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, ]