Skip to content

Commit d5f1785

Browse files
Illviljanpre-commit-ci[bot]headtr1ckandersy005
authored
Use strict type hinting for namedarray (#8241)
* Disallow untyped defs in namedarray * Just use strict instead * Update pyproject.toml * Test explicit list instead. * Update pyproject.toml * Update pyproject.toml * Update pyproject.toml * Update utils.py * Update core.py * getmaskarray isn't typed yet * Update core.py * add _Array protocol * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update test_namedarray.py * Update utils.py * Update test_namedarray.py * Update test_namedarray.py * Update utils.py * Update utils.py * Update utils.py * Update core.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update utils.py * Update core.py * Update test_namedarray.py * Update test_namedarray.py * Update test_namedarray.py * Update utils.py * Update core.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update core.py * Update core.py * Update utils.py * Update core.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update core.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update core.py * Update test_namedarray.py * Update utils.py * Update pyproject.toml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update core.py * Update utils.py * Update xarray/namedarray/utils.py Co-authored-by: Michael Niklas <[email protected]> * Update utils.py * Update core.py * Update utils.py * Update core.py * Update utils.py * Update core.py * Update core.py * Update core.py * Update test_namedarray.py * Update utils.py * Update core.py * Update utils.py * Update test_namedarray.py * Update test_namedarray.py * Update core.py * Update parallel.py * Update utils.py * fixes * Update utils.py * Update utils.py * ignores * Update xarray/namedarray/utils.py Co-authored-by: Michael Niklas <[email protected]> * Update xarray/namedarray/utils.py Co-authored-by: Michael Niklas <[email protected]> * Update core.py * Update test_namedarray.py * Update core.py * Update core.py * Update core.py * Update core.py * Update test_namedarray.py * Update core.py * Update test_namedarray.py * import specific type functions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update core.py * Update core.py * Update core.py * Try chunkedarray instead * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixes * Update core.py * Update core.py * Update core.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update core.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Michael Niklas <[email protected]> Co-authored-by: Anderson Banihirwe <[email protected]>
1 parent a1d168d commit d5f1785

File tree

5 files changed

+304
-98
lines changed

5 files changed

+304
-98
lines changed

pyproject.toml

+36
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ module = [
9393
"cftime.*",
9494
"cubed.*",
9595
"cupy.*",
96+
"dask.types.*",
9697
"fsspec.*",
9798
"h5netcdf.*",
9899
"h5py.*",
@@ -162,6 +163,41 @@ module = [
162163
"xarray.tests.test_weighted",
163164
]
164165

166+
# Use strict = true whenever namedarray has become standalone. In the meantime
167+
# don't forget to add all new files related to namedarray here:
168+
# ref: https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options
169+
[[tool.mypy.overrides]]
170+
# Start off with these
171+
warn_unused_configs = true
172+
warn_redundant_casts = true
173+
warn_unused_ignores = true
174+
175+
# Getting these passing should be easy
176+
strict_equality = true
177+
strict_concatenate = true
178+
179+
# Strongly recommend enabling this one as soon as you can
180+
check_untyped_defs = true
181+
182+
# These shouldn't be too much additional work, but may be tricky to
183+
# get passing if you use a lot of untyped libraries
184+
disallow_subclassing_any = true
185+
disallow_untyped_decorators = true
186+
disallow_any_generics = true
187+
188+
# These next few are various gradations of forcing use of type annotations
189+
disallow_untyped_calls = true
190+
disallow_incomplete_defs = true
191+
disallow_untyped_defs = true
192+
193+
# This one isn't too hard to get passing, but return on investment is lower
194+
no_implicit_reexport = true
195+
196+
# This one can be tricky to get passing if you use a lot of untyped libraries
197+
warn_return_any = true
198+
199+
module = ["xarray.namedarray.*", "xarray.tests.test_namedarray"]
200+
165201
[tool.ruff]
166202
builtins = ["ellipsis"]
167203
exclude = [

xarray/core/parallel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def subset_dataset_to_block(
443443
for dim in variable.dims:
444444
chunk = chunk[chunk_index[dim]]
445445

446-
chunk_variable_task = (f"{name}-{gname}-{chunk[0]}",) + chunk_tuple
446+
chunk_variable_task = (f"{name}-{gname}-{chunk[0]!r}",) + chunk_tuple
447447
graph[chunk_variable_task] = (
448448
tuple,
449449
[variable.dims, chunk, variable.attrs],

0 commit comments

Comments
 (0)