1
1
"""Internal utilities; not for external use"""
2
+ from __future__ import annotations
3
+
2
4
import contextlib
3
5
import functools
4
6
import io
14
16
Callable ,
15
17
Collection ,
16
18
Container ,
17
- Dict ,
18
19
Hashable ,
19
20
Iterable ,
20
21
Iterator ,
21
22
Mapping ,
22
23
MutableMapping ,
23
24
MutableSet ,
24
- Optional ,
25
25
Sequence ,
26
- Tuple ,
27
26
TypeVar ,
28
- Union ,
29
27
cast ,
30
28
)
31
29
@@ -188,7 +186,7 @@ def list_equiv(first, second):
188
186
return equiv
189
187
190
188
191
- def peek_at (iterable : Iterable [T ]) -> Tuple [T , Iterator [T ]]:
189
+ def peek_at (iterable : Iterable [T ]) -> tuple [T , Iterator [T ]]:
192
190
"""Returns the first value from iterable, as well as a new iterator with
193
191
the same content as the original iterable
194
192
"""
@@ -273,7 +271,7 @@ def is_duck_array(value: Any) -> bool:
273
271
274
272
275
273
def either_dict_or_kwargs (
276
- pos_kwargs : Optional [ Mapping [Any , T ]] ,
274
+ pos_kwargs : Mapping [Any , T ] | None ,
277
275
kw_kwargs : Mapping [str , T ],
278
276
func_name : str ,
279
277
) -> Mapping [Hashable , T ]:
@@ -511,7 +509,7 @@ class OrderedSet(MutableSet[T]):
511
509
a dict. Note that, unlike in an OrderedDict, equality tests are not order-sensitive.
512
510
"""
513
511
514
- _d : Dict [T , None ]
512
+ _d : dict [T , None ]
515
513
516
514
__slots__ = ("_d" ,)
517
515
@@ -585,7 +583,7 @@ def dtype(self: Any) -> np.dtype:
585
583
return self .array .dtype
586
584
587
585
@property
588
- def shape (self : Any ) -> Tuple [int ]:
586
+ def shape (self : Any ) -> tuple [int ]:
589
587
return self .array .shape
590
588
591
589
def __getitem__ (self : Any , key ):
@@ -659,7 +657,7 @@ def read_magic_number_from_file(filename_or_obj, count=8) -> bytes:
659
657
return magic_number
660
658
661
659
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 :
663
661
if isinstance (pathlike , str ) or hasattr (pathlike , "__fspath__" ):
664
662
path = os .fspath (pathlike )
665
663
try :
@@ -670,9 +668,7 @@ def try_read_magic_number_from_path(pathlike, count=8) -> Optional[bytes]:
670
668
return None
671
669
672
670
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 :
676
672
magic_number = try_read_magic_number_from_path (filename_or_obj , count )
677
673
if magic_number is None :
678
674
try :
@@ -706,7 +702,7 @@ def hashable(v: Any) -> bool:
706
702
return True
707
703
708
704
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 ]:
710
706
"""Convert attribute values from numpy objects to native Python objects,
711
707
for use in to_dict
712
708
"""
@@ -815,7 +811,7 @@ def get_temp_dimname(dims: Container[Hashable], new_dim: Hashable) -> Hashable:
815
811
816
812
def drop_dims_from_indexers (
817
813
indexers : Mapping [Any , Any ],
818
- dims : Union [ list , Mapping [Any , int ] ],
814
+ dims : list | Mapping [Any , int ],
819
815
missing_dims : str ,
820
816
) -> Mapping [Hashable , Any ]:
821
817
"""Depending on the setting of missing_dims, drop any dimensions from indexers that
0 commit comments