diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 679ac50e641..8e5b8caf0d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: - id: rst-inline-touching-normal - id: text-unicode-replacement-char - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.20 + rev: v0.16.1 hooks: - id: ruff-check args: ["--fix", "--show-fixes"] @@ -37,12 +37,12 @@ repos: # make sure this is the most recent version of black additional_dependencies: ["black==25.11.0"] - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.9.4 + rev: v3.9.6 hooks: - id: prettier args: ["--cache-location=.prettier_cache/cache"] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v2.1.0 + rev: v2.3.0 hooks: - id: mypy # Copied from setup.cfg @@ -80,7 +80,7 @@ repos: hooks: - id: typos - repo: https://github.com/zizmorcore/zizmor-pre-commit - rev: v1.26.1 + rev: v1.29.0 hooks: - id: zizmor args: ["--offline"] diff --git a/xarray/backends/api.py b/xarray/backends/api.py index 4330eb21cc6..743890675b3 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -1400,7 +1400,7 @@ def open_mfdataset( preprocess: Callable[[Dataset], Dataset] | None = None, engine: T_Engine = None, data_vars: ( - Literal["all", "minimal", "different"] | None | list[str] | CombineKwargDefault + Literal["all", "minimal", "different"] | list[str] | CombineKwargDefault | None ) = _DATA_VARS_DEFAULT, coords=_COORDS_DEFAULT, combine: Literal["by_coords", "nested"] = "by_coords", diff --git a/xarray/backends/file_manager.py b/xarray/backends/file_manager.py index e6f94f93668..ec31b8aa04b 100644 --- a/xarray/backends/file_manager.py +++ b/xarray/backends/file_manager.py @@ -89,7 +89,7 @@ def __init__( *args: Any, mode: Any = _OMIT_MODE, kwargs: Mapping[str, Any] | None = None, - lock: Lock | None | Literal[False] = None, + lock: Lock | Literal[False] | None = None, cache: MutableMapping[Any, T_File] | None = None, manager_id: Hashable | None = None, ref_counts: dict[Any, int] | None = None, @@ -355,7 +355,7 @@ def __init__( opener: Callable[..., T_File], *args: Any, mode: Any = _OMIT_MODE, - lock: Lock | None | Literal[False] = None, + lock: Lock | Literal[False] | None = None, kwargs: Mapping[str, Any] | None = None, ): kwargs = {} if kwargs is None else dict(kwargs) @@ -458,7 +458,7 @@ def __init__( value: T_File, *, close: Callable[[], None] | None = None, - lock: Lock | None | Literal[False] = None, + lock: Lock | Literal[False] | None = None, ): if close is None: close = value.close diff --git a/xarray/backends/locks.py b/xarray/backends/locks.py index 2b84f932843..1c6d673cdad 100644 --- a/xarray/backends/locks.py +++ b/xarray/backends/locks.py @@ -276,7 +276,7 @@ def combine_locks(locks: Sequence[Lock]) -> Lock: return DummyLock() -def ensure_lock(lock: Lock | None | Literal[False]) -> Lock: +def ensure_lock(lock: Lock | Literal[False] | None) -> Lock: """Ensure that the given object is a lock.""" if lock is None or lock is False: return DummyLock() diff --git a/xarray/backends/store.py b/xarray/backends/store.py index 2c3cd42ae92..3f3bdcd277b 100644 --- a/xarray/backends/store.py +++ b/xarray/backends/store.py @@ -1,7 +1,6 @@ from __future__ import annotations from collections.abc import Iterable -from typing import TYPE_CHECKING from xarray import conventions from xarray.backends.common import ( @@ -13,9 +12,6 @@ from xarray.core.coordinates import Coordinates from xarray.core.dataset import Dataset -if TYPE_CHECKING: - pass - class StoreBackendEntrypoint(BackendEntrypoint): description = "Open AbstractDataStore instances in Xarray" diff --git a/xarray/backends/writers.py b/xarray/backends/writers.py index 77de8aa892d..b1881efd1ea 100644 --- a/xarray/backends/writers.py +++ b/xarray/backends/writers.py @@ -801,7 +801,7 @@ def _datatree_to_netcdf( compute: bool = True, invalid_netcdf: bool = False, auto_complex: bool | None = None, -) -> None | memoryview | Delayed: +) -> memoryview | Delayed | None: """Implementation of `DataTree.to_netcdf`.""" if format not in [None, *get_args(T_DataTreeNetcdfTypes)]: diff --git a/xarray/coding/strings.py b/xarray/coding/strings.py index 0869b3072b3..dfa02929e79 100644 --- a/xarray/coding/strings.py +++ b/xarray/coding/strings.py @@ -60,7 +60,7 @@ def encode(self, variable: Variable, name=None) -> Variable: # which all backends support natively (GH11199) if data.dtype.kind == "T": data = np.asarray(data, dtype=object) - data[data == None] = "" # noqa: E711 + data[data == None] = "" data = np.asarray(data, dtype="U") variable = Variable(dims, data, attrs, encoding) diff --git a/xarray/coding/times.py b/xarray/coding/times.py index 6298a9a92bd..8d89c347722 100644 --- a/xarray/coding/times.py +++ b/xarray/coding/times.py @@ -976,7 +976,7 @@ def _encode_datetime_with_cftime(dates, units: str, calendar: str) -> np.ndarray dates = np.atleast_1d(dates) # Find all the None position - none_position = dates == None # noqa: E711 + none_position = dates == None filtered_dates = dates[~none_position] # Since netCDF files do not support storing float128 values, we ensure diff --git a/xarray/computation/ops.py b/xarray/computation/ops.py index 1514f1694ca..7795080fad7 100644 --- a/xarray/computation/ops.py +++ b/xarray/computation/ops.py @@ -8,15 +8,12 @@ from __future__ import annotations import operator -from typing import TYPE_CHECKING, Literal +from typing import Literal import numpy as np from xarray.core import dtypes, duck_array_ops -if TYPE_CHECKING: - pass - try: import bottleneck as bn diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index c8db4de9226..89033535782 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -3571,13 +3571,13 @@ def interpolate_na( limit: int | None = None, use_coordinate: bool | str = True, max_gap: ( - None - | int + int | float | str | pd.Timedelta | np.timedelta64 | datetime.timedelta + | None ) = None, keep_attrs: bool | None = None, **kwargs: Any, diff --git a/xarray/core/datatree.py b/xarray/core/datatree.py index 98934f29b92..1d75c887584 100644 --- a/xarray/core/datatree.py +++ b/xarray/core/datatree.py @@ -1811,7 +1811,7 @@ def map_over_datasets( def map_over_datasets( self, - func: Callable[..., Dataset | None | tuple[Dataset | None, ...]], + func: Callable[..., Dataset | tuple[Dataset | None, ...] | None], *args: Any, kwargs: Mapping[str, Any] | None = None, ) -> DataTree | tuple[DataTree, ...]: @@ -2034,7 +2034,7 @@ def to_netcdf( write_inherited_coords: bool = False, compute: bool = True, **kwargs, - ) -> None | memoryview | Delayed: + ) -> memoryview | Delayed | None: """ Write datatree contents to a netCDF file. diff --git a/xarray/core/datatree_mapping.py b/xarray/core/datatree_mapping.py index 2bed7c8f1ca..04741aa72ad 100644 --- a/xarray/core/datatree_mapping.py +++ b/xarray/core/datatree_mapping.py @@ -39,7 +39,7 @@ def map_over_datasets( def map_over_datasets( - func: Callable[..., Dataset | None | tuple[Dataset | None, ...]], + func: Callable[..., Dataset | tuple[Dataset | None, ...] | None], *args: Any, kwargs: Mapping[str, Any] | None = None, ) -> DataTree | tuple[DataTree, ...]: diff --git a/xarray/structure/combine.py b/xarray/structure/combine.py index 6699b32d8fa..0ba6dc4dc14 100644 --- a/xarray/structure/combine.py +++ b/xarray/structure/combine.py @@ -799,9 +799,9 @@ def combine_by_coords( data_objects: Iterable[Dataset | DataArray] = [], compat: CompatOptions | CombineKwargDefault = _COMPAT_DEFAULT, data_vars: Literal["all", "minimal", "different"] - | None | list[str] - | CombineKwargDefault = _DATA_VARS_DEFAULT, + | CombineKwargDefault + | None = _DATA_VARS_DEFAULT, coords: str | CombineKwargDefault = _COORDS_DEFAULT, fill_value: object = dtypes.NA, join: JoinOptions | CombineKwargDefault = _JOIN_DEFAULT, diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index b2619008379..a721656bfbb 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -6616,7 +6616,7 @@ def test_argmin_dim( minindices_x = { key: xr.where( - nanindices_x[key] == None, # noqa: E711 + nanindices_x[key] == None, minindices_x[key], nanindices_x[key], ) @@ -6634,7 +6634,7 @@ def test_argmin_dim( minindices_y = { key: xr.where( - nanindices_y[key] == None, # noqa: E711 + nanindices_y[key] == None, minindices_y[key], nanindices_y[key], ) @@ -6652,7 +6652,7 @@ def test_argmin_dim( minindices_z = { key: xr.where( - nanindices_z[key] == None, # noqa: E711 + nanindices_z[key] == None, minindices_z[key], nanindices_z[key], ) @@ -6670,7 +6670,7 @@ def test_argmin_dim( minindices_xy = { key: xr.where( - nanindices_xy[key] == None, # noqa: E711 + nanindices_xy[key] == None, minindices_xy[key], nanindices_xy[key], ) @@ -6688,7 +6688,7 @@ def test_argmin_dim( minindices_xz = { key: xr.where( - nanindices_xz[key] == None, # noqa: E711 + nanindices_xz[key] == None, minindices_xz[key], nanindices_xz[key], ) @@ -6706,7 +6706,7 @@ def test_argmin_dim( minindices_yz = { key: xr.where( - nanindices_yz[key] == None, # noqa: E711 + nanindices_yz[key] == None, minindices_yz[key], nanindices_yz[key], ) @@ -6724,7 +6724,7 @@ def test_argmin_dim( minindices_xyz = { key: xr.where( - nanindices_xyz[key] == None, # noqa: E711 + nanindices_xyz[key] == None, minindices_xyz[key], nanindices_xyz[key], ) @@ -6855,7 +6855,7 @@ def test_argmax_dim( maxindices_x = { key: xr.where( - nanindices_x[key] == None, # noqa: E711 + nanindices_x[key] == None, maxindices_x[key], nanindices_x[key], ) @@ -6873,7 +6873,7 @@ def test_argmax_dim( maxindices_y = { key: xr.where( - nanindices_y[key] == None, # noqa: E711 + nanindices_y[key] == None, maxindices_y[key], nanindices_y[key], ) @@ -6891,7 +6891,7 @@ def test_argmax_dim( maxindices_z = { key: xr.where( - nanindices_z[key] == None, # noqa: E711 + nanindices_z[key] == None, maxindices_z[key], nanindices_z[key], ) @@ -6909,7 +6909,7 @@ def test_argmax_dim( maxindices_xy = { key: xr.where( - nanindices_xy[key] == None, # noqa: E711 + nanindices_xy[key] == None, maxindices_xy[key], nanindices_xy[key], ) @@ -6927,7 +6927,7 @@ def test_argmax_dim( maxindices_xz = { key: xr.where( - nanindices_xz[key] == None, # noqa: E711 + nanindices_xz[key] == None, maxindices_xz[key], nanindices_xz[key], ) @@ -6945,7 +6945,7 @@ def test_argmax_dim( maxindices_yz = { key: xr.where( - nanindices_yz[key] == None, # noqa: E711 + nanindices_yz[key] == None, maxindices_yz[key], nanindices_yz[key], ) @@ -6963,7 +6963,7 @@ def test_argmax_dim( maxindices_xyz = { key: xr.where( - nanindices_xyz[key] == None, # noqa: E711 + nanindices_xyz[key] == None, maxindices_xyz[key], nanindices_xyz[key], ) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 3d7d11317c0..48de68c7a44 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1685,7 +1685,7 @@ def test_convenient_facetgrid_4d(self) -> None: def test_facetgrid_col_wrap_auto( self, n: int, - figsize: None | tuple[int, int], + figsize: tuple[int, int] | None, aspect: int, expected_shape: tuple[int, int], ) -> None: