Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions xarray/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Internal utilities; not for external use"""
from __future__ import annotations

import contextlib
import functools
import io
Expand All @@ -14,18 +16,14 @@
Callable,
Collection,
Container,
Dict,
Hashable,
Iterable,
Iterator,
Mapping,
MutableMapping,
MutableSet,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
cast,
)

Expand Down Expand Up @@ -188,7 +186,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
"""
Expand Down Expand Up @@ -273,7 +271,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]:
Expand Down Expand Up @@ -511,7 +509,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",)

Expand Down Expand Up @@ -585,7 +583,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):
Expand Down Expand Up @@ -659,7 +657,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:
Expand All @@ -670,9 +668,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:
Expand Down Expand Up @@ -706,7 +702,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
"""
Expand Down Expand Up @@ -815,7 +811,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
Expand Down