Skip to content

Fixed type errors in mypy GitHub Action #6963

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

Merged
merged 12 commits into from
Nov 21, 2022
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'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is mypy=0.990 still crashing?


- name: Run mypy
run: |
python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report

- name: Upload mypy coverage to Codecov
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to upload this to codecov? The coverage should be the same as for the newest python.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, I just kept it simple with the copy/pasting as I suspect we can do this workflow in a smarter way; similar way as the pytest CI or the mypy --python-version 3.8-way.

I think we can just focus on getting the xarray bugs fixed in this PR and not get stuck with the CI semantics.

uses: codecov/[email protected]
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