From 9af5e4aad13e5fea66fc0cd470fdd651fe7eb2e6 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sat, 5 Feb 2022 10:38:59 +0100 Subject: [PATCH 1/3] Run pyupgrade on core/utils --- xarray/core/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xarray/core/utils.py b/xarray/core/utils.py index a9ea0acb267..84023bc6bf1 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -1,4 +1,6 @@ """Internal utilities; not for external use""" +from __future__ import annotations + import contextlib import functools import io From afe51f5b791ba5a01988fd8054bb22e72c76bd1b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Feb 2022 09:41:39 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/utils.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/xarray/core/utils.py b/xarray/core/utils.py index 84023bc6bf1..eab45ad2ac5 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -190,7 +190,7 @@ def list_equiv(first, second): return equiv -def peek_at(iterable: Iterable[T]) -> Tuple[T, Iterator[T]]: +def peek_at(iterable: Iterable[T]) -> tuple[T, Iterator[T]]: """Returns the first value from iterable, as well as a new iterator with the same content as the original iterable """ @@ -275,7 +275,7 @@ def is_duck_array(value: Any) -> bool: def either_dict_or_kwargs( - pos_kwargs: Optional[Mapping[Any, T]], + pos_kwargs: Mapping[Any, T] | None, kw_kwargs: Mapping[str, T], func_name: str, ) -> Mapping[Hashable, T]: @@ -513,7 +513,7 @@ class OrderedSet(MutableSet[T]): a dict. Note that, unlike in an OrderedDict, equality tests are not order-sensitive. """ - _d: Dict[T, None] + _d: dict[T, None] __slots__ = ("_d",) @@ -587,7 +587,7 @@ def dtype(self: Any) -> np.dtype: return self.array.dtype @property - def shape(self: Any) -> Tuple[int]: + def shape(self: Any) -> tuple[int]: return self.array.shape def __getitem__(self: Any, key): @@ -661,7 +661,7 @@ def read_magic_number_from_file(filename_or_obj, count=8) -> bytes: return magic_number -def try_read_magic_number_from_path(pathlike, count=8) -> Optional[bytes]: +def try_read_magic_number_from_path(pathlike, count=8) -> bytes | None: if isinstance(pathlike, str) or hasattr(pathlike, "__fspath__"): path = os.fspath(pathlike) try: @@ -672,9 +672,7 @@ def try_read_magic_number_from_path(pathlike, count=8) -> Optional[bytes]: return None -def try_read_magic_number_from_file_or_path( - filename_or_obj, count=8 -) -> Optional[bytes]: +def try_read_magic_number_from_file_or_path(filename_or_obj, count=8) -> bytes | None: magic_number = try_read_magic_number_from_path(filename_or_obj, count) if magic_number is None: try: @@ -708,7 +706,7 @@ def hashable(v: Any) -> bool: return True -def decode_numpy_dict_values(attrs: Mapping[K, V]) -> Dict[K, V]: +def decode_numpy_dict_values(attrs: Mapping[K, V]) -> dict[K, V]: """Convert attribute values from numpy objects to native Python objects, for use in to_dict """ @@ -817,7 +815,7 @@ def get_temp_dimname(dims: Container[Hashable], new_dim: Hashable) -> Hashable: def drop_dims_from_indexers( indexers: Mapping[Any, Any], - dims: Union[list, Mapping[Any, int]], + dims: list | Mapping[Any, int], missing_dims: str, ) -> Mapping[Hashable, Any]: """Depending on the setting of missing_dims, drop any dimensions from indexers that From 2fd532492756b62ff738eb6317821e90e6cf2ac3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Feb 2022 09:50:13 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/utils.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/xarray/core/utils.py b/xarray/core/utils.py index eab45ad2ac5..da3a196a621 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -16,18 +16,14 @@ Callable, Collection, Container, - Dict, Hashable, Iterable, Iterator, Mapping, MutableMapping, MutableSet, - Optional, Sequence, - Tuple, TypeVar, - Union, cast, )