Skip to content

Commit

Permalink
Fixed type errors in mypy GitHub Action (#6963)
Browse files Browse the repository at this point in the history
* fixed mypy type errors

* add mypy with python3.8 to ci

* fix mypy python 3.8 problems

* add verbosity flag to mypy action

* silence import errors in mypy python 3.8

* Test copying the entire workflow.

* Update ci-additional.yaml

* Last test running 3.8 inside mypy workflow

* Update ci-additional.yaml

* Use the copy/pasted workflow only

Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
Co-authored-by: Michael Niklas <mick.niklas@gmail.com>
Co-authored-by: Illviljan <14371165+Illviljan@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 21, 2022
1 parent 27d02a7 commit 88a75c9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/ci-additional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
TYPE_CHECKING,
Any,
Callable,
Dict,
Final,
Hashable,
Iterable,
Expand Down Expand Up @@ -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"
]
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
10 changes: 6 additions & 4 deletions xarray/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
Callable,
Hashable,
Iterable,
List,
Literal,
Protocol,
Sequence,
SupportsIndex,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -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,
]
Expand Down

0 comments on commit 88a75c9

Please sign in to comment.