Skip to content

Commit 88a75c9

Browse files
lukeconibeardcherianheadtr1ckIllviljan
authored
Fixed type errors in mypy GitHub Action (#6963)
* 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 <[email protected]> Co-authored-by: Michael Niklas <[email protected]> Co-authored-by: Illviljan <[email protected]>
1 parent 27d02a7 commit 88a75c9

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

.github/workflows/ci-additional.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,64 @@ jobs:
134134
name: codecov-umbrella
135135
fail_ci_if_error: false
136136

137+
mypy38:
138+
name: Mypy 3.8
139+
runs-on: "ubuntu-latest"
140+
needs: detect-ci-trigger
141+
# temporarily skipping due to https://github.com/pydata/xarray/issues/6551
142+
if: needs.detect-ci-trigger.outputs.triggered == 'false'
143+
defaults:
144+
run:
145+
shell: bash -l {0}
146+
env:
147+
CONDA_ENV_FILE: ci/requirements/environment.yml
148+
PYTHON_VERSION: "3.8"
149+
150+
steps:
151+
- uses: actions/checkout@v3
152+
with:
153+
fetch-depth: 0 # Fetch all history for all branches and tags.
154+
155+
- name: set environment variables
156+
run: |
157+
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
158+
- name: Setup micromamba
159+
uses: mamba-org/provision-with-micromamba@v14
160+
with:
161+
environment-file: ${{env.CONDA_ENV_FILE}}
162+
environment-name: xarray-tests
163+
extra-specs: |
164+
python=${{env.PYTHON_VERSION}}
165+
conda
166+
cache-env: true
167+
cache-env-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
168+
- name: Install xarray
169+
run: |
170+
python -m pip install --no-deps -e .
171+
- name: Version info
172+
run: |
173+
conda info -a
174+
conda list
175+
python xarray/util/print_versions.py
176+
- name: Install mypy
177+
run: |
178+
python -m pip install 'mypy<0.990'
179+
180+
- name: Run mypy
181+
run: |
182+
python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report
183+
184+
- name: Upload mypy coverage to Codecov
185+
uses: codecov/[email protected]
186+
with:
187+
file: mypy_report/cobertura.xml
188+
flags: mypy38
189+
env_vars: PYTHON_VERSION
190+
name: codecov-umbrella
191+
fail_ci_if_error: false
192+
193+
194+
137195
min-version-policy:
138196
name: Minimum Version Policy
139197
runs-on: "ubuntu-latest"

xarray/backends/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
TYPE_CHECKING,
1010
Any,
1111
Callable,
12+
Dict,
1213
Final,
1314
Hashable,
1415
Iterable,
@@ -62,7 +63,7 @@
6263
str, # no nice typing support for custom backends
6364
None,
6465
]
65-
T_Chunks = Union[int, dict[Any, Any], Literal["auto"], None]
66+
T_Chunks = Union[int, Dict[Any, Any], Literal["auto"], None]
6667
T_NetcdfTypes = Literal[
6768
"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", "NETCDF3_CLASSIC"
6869
]

xarray/core/merge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
ArrayLike = Any
4141
VariableLike = Union[
4242
ArrayLike,
43-
tuple[DimsLike, ArrayLike],
44-
tuple[DimsLike, ArrayLike, Mapping],
45-
tuple[DimsLike, ArrayLike, Mapping, Mapping],
43+
Tuple[DimsLike, ArrayLike],
44+
Tuple[DimsLike, ArrayLike, Mapping],
45+
Tuple[DimsLike, ArrayLike, Mapping, Mapping],
4646
]
4747
XarrayValue = Union[DataArray, Variable, VariableLike]
4848
DatasetLike = Union[Dataset, Mapping[Any, XarrayValue]]

xarray/core/types.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
Callable,
77
Hashable,
88
Iterable,
9+
List,
910
Literal,
1011
Protocol,
1112
Sequence,
1213
SupportsIndex,
14+
Tuple,
1315
TypeVar,
1416
Union,
1517
)
@@ -70,13 +72,13 @@ def dtype(self) -> np.dtype:
7072
# character codes, type strings or comma-separated fields, e.g., 'float64'
7173
str,
7274
# (flexible_dtype, itemsize)
73-
tuple[_DTypeLikeNested, int],
75+
Tuple[_DTypeLikeNested, int],
7476
# (fixed_dtype, shape)
75-
tuple[_DTypeLikeNested, _ShapeLike],
77+
Tuple[_DTypeLikeNested, _ShapeLike],
7678
# (base_dtype, new_dtype)
77-
tuple[_DTypeLikeNested, _DTypeLikeNested],
79+
Tuple[_DTypeLikeNested, _DTypeLikeNested],
7880
# because numpy does the same?
79-
list[Any],
81+
List[Any],
8082
# anything with a dtype attribute
8183
_SupportsDType,
8284
]

0 commit comments

Comments
 (0)