Skip to content

Commit 56122ef

Browse files
Run pyupgrade on core/utils (#6240)
* Run pyupgrade on core/utils * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 33067cd commit 56122ef

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

xarray/core/utils.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Internal utilities; not for external use"""
2+
from __future__ import annotations
3+
24
import contextlib
35
import functools
46
import io
@@ -14,18 +16,14 @@
1416
Callable,
1517
Collection,
1618
Container,
17-
Dict,
1819
Hashable,
1920
Iterable,
2021
Iterator,
2122
Mapping,
2223
MutableMapping,
2324
MutableSet,
24-
Optional,
2525
Sequence,
26-
Tuple,
2726
TypeVar,
28-
Union,
2927
cast,
3028
)
3129

@@ -188,7 +186,7 @@ def list_equiv(first, second):
188186
return equiv
189187

190188

191-
def peek_at(iterable: Iterable[T]) -> Tuple[T, Iterator[T]]:
189+
def peek_at(iterable: Iterable[T]) -> tuple[T, Iterator[T]]:
192190
"""Returns the first value from iterable, as well as a new iterator with
193191
the same content as the original iterable
194192
"""
@@ -273,7 +271,7 @@ def is_duck_array(value: Any) -> bool:
273271

274272

275273
def either_dict_or_kwargs(
276-
pos_kwargs: Optional[Mapping[Any, T]],
274+
pos_kwargs: Mapping[Any, T] | None,
277275
kw_kwargs: Mapping[str, T],
278276
func_name: str,
279277
) -> Mapping[Hashable, T]:
@@ -511,7 +509,7 @@ class OrderedSet(MutableSet[T]):
511509
a dict. Note that, unlike in an OrderedDict, equality tests are not order-sensitive.
512510
"""
513511

514-
_d: Dict[T, None]
512+
_d: dict[T, None]
515513

516514
__slots__ = ("_d",)
517515

@@ -585,7 +583,7 @@ def dtype(self: Any) -> np.dtype:
585583
return self.array.dtype
586584

587585
@property
588-
def shape(self: Any) -> Tuple[int]:
586+
def shape(self: Any) -> tuple[int]:
589587
return self.array.shape
590588

591589
def __getitem__(self: Any, key):
@@ -659,7 +657,7 @@ def read_magic_number_from_file(filename_or_obj, count=8) -> bytes:
659657
return magic_number
660658

661659

662-
def try_read_magic_number_from_path(pathlike, count=8) -> Optional[bytes]:
660+
def try_read_magic_number_from_path(pathlike, count=8) -> bytes | None:
663661
if isinstance(pathlike, str) or hasattr(pathlike, "__fspath__"):
664662
path = os.fspath(pathlike)
665663
try:
@@ -670,9 +668,7 @@ def try_read_magic_number_from_path(pathlike, count=8) -> Optional[bytes]:
670668
return None
671669

672670

673-
def try_read_magic_number_from_file_or_path(
674-
filename_or_obj, count=8
675-
) -> Optional[bytes]:
671+
def try_read_magic_number_from_file_or_path(filename_or_obj, count=8) -> bytes | None:
676672
magic_number = try_read_magic_number_from_path(filename_or_obj, count)
677673
if magic_number is None:
678674
try:
@@ -706,7 +702,7 @@ def hashable(v: Any) -> bool:
706702
return True
707703

708704

709-
def decode_numpy_dict_values(attrs: Mapping[K, V]) -> Dict[K, V]:
705+
def decode_numpy_dict_values(attrs: Mapping[K, V]) -> dict[K, V]:
710706
"""Convert attribute values from numpy objects to native Python objects,
711707
for use in to_dict
712708
"""
@@ -815,7 +811,7 @@ def get_temp_dimname(dims: Container[Hashable], new_dim: Hashable) -> Hashable:
815811

816812
def drop_dims_from_indexers(
817813
indexers: Mapping[Any, Any],
818-
dims: Union[list, Mapping[Any, int]],
814+
dims: list | Mapping[Any, int],
819815
missing_dims: str,
820816
) -> Mapping[Hashable, Any]:
821817
"""Depending on the setting of missing_dims, drop any dimensions from indexers that

0 commit comments

Comments
 (0)