Skip to content

Commit 515951c

Browse files
committed
Rename Path newtype to PathType
With the use of pathlib.Path in the library, this could get confusing.
1 parent 063a08f commit 515951c

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

zarr/storage.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import multiprocessing
2121
import operator
2222
import os
23-
from pathlib import Path
2423
import re
2524
import shutil
2625
import sys
@@ -78,7 +77,7 @@
7877
default_compressor = Zlib()
7978

8079

81-
Path = Union[str, bytes, None]
80+
PathType = Union[str, bytes, None]
8281

8382

8483
def _path_to_prefix(path: Optional[str]) -> str:
@@ -90,15 +89,15 @@ def _path_to_prefix(path: Optional[str]) -> str:
9089
return prefix
9190

9291

93-
def contains_array(store: MutableMapping, path: Path = None) -> bool:
92+
def contains_array(store: MutableMapping, path: PathType = None) -> bool:
9493
"""Return True if the store contains an array at the given logical path."""
9594
path = normalize_storage_path(path)
9695
prefix = _path_to_prefix(path)
9796
key = prefix + array_meta_key
9897
return key in store
9998

10099

101-
def contains_group(store: MutableMapping, path: Path = None) -> bool:
100+
def contains_group(store: MutableMapping, path: PathType = None) -> bool:
102101
"""Return True if the store contains a group at the given logical path."""
103102
path = normalize_storage_path(path)
104103
prefix = _path_to_prefix(path)
@@ -114,7 +113,7 @@ def _rmdir_from_keys(store: MutableMapping, path: Optional[str] = None) -> None:
114113
del store[key]
115114

116115

117-
def rmdir(store, path: Path = None):
116+
def rmdir(store, path: PathType = None):
118117
"""Remove all items under the given path. If `store` provides a `rmdir` method,
119118
this will be called, otherwise will fall back to implementation via the
120119
`MutableMapping` interface."""
@@ -137,7 +136,7 @@ def _rename_from_keys(store: MutableMapping, src_path: str, dst_path: str) -> No
137136
store[new_key] = store.pop(key)
138137

139138

140-
def rename(store, src_path: Path, dst_path: Path):
139+
def rename(store, src_path: PathType, dst_path: PathType):
141140
"""Rename all items under the given path. If `store` provides a `rename` method,
142141
this will be called, otherwise will fall back to implementation via the
143142
`MutableMapping` interface."""
@@ -163,7 +162,7 @@ def _listdir_from_keys(store: MutableMapping, path: Optional[str] = None) -> Lis
163162
return sorted(children)
164163

165164

166-
def listdir(store, path: Path = None):
165+
def listdir(store, path: PathType = None):
167166
"""Obtain a directory listing for the given path. If `store` provides a `listdir`
168167
method, this will be called, otherwise will fall back to implementation via the
169168
`MutableMapping` interface."""
@@ -176,7 +175,7 @@ def listdir(store, path: Path = None):
176175
return _listdir_from_keys(store, path)
177176

178177

179-
def getsize(store, path: Path = None) -> int:
178+
def getsize(store, path: PathType = None) -> int:
180179
"""Compute size of stored items for a given path. If `store` provides a `getsize`
181180
method, this will be called, otherwise will return -1."""
182181
path = normalize_storage_path(path)
@@ -234,7 +233,7 @@ def init_array(
234233
fill_value=None,
235234
order: str = "C",
236235
overwrite: bool = False,
237-
path: Path = None,
236+
path: PathType = None,
238237
chunk_store: MutableMapping = None,
239238
filters=None,
240239
object_codec=None,
@@ -459,7 +458,7 @@ def _init_array_metadata(
459458
def init_group(
460459
store: MutableMapping,
461460
overwrite: bool = False,
462-
path: Path = None,
461+
path: PathType = None,
463462
chunk_store: MutableMapping = None,
464463
):
465464
"""Initialize a group store. Note that this is a low-level function and there should be no
@@ -648,7 +647,7 @@ def __iter__(self):
648647
def __len__(self) -> int:
649648
return sum(1 for _ in self.keys())
650649

651-
def listdir(self, path: Path = None) -> List[str]:
650+
def listdir(self, path: PathType = None) -> List[str]:
652651
path = normalize_storage_path(path)
653652
if path:
654653
try:
@@ -663,7 +662,7 @@ def listdir(self, path: Path = None) -> List[str]:
663662
else:
664663
return []
665664

666-
def rename(self, src_path: Path, dst_path: Path):
665+
def rename(self, src_path: PathType, dst_path: PathType):
667666
src_path = normalize_storage_path(src_path)
668667
dst_path = normalize_storage_path(dst_path)
669668

@@ -672,7 +671,7 @@ def rename(self, src_path: Path, dst_path: Path):
672671

673672
dst_parent[dst_key] = src_parent.pop(src_key)
674673

675-
def rmdir(self, path: Path = None):
674+
def rmdir(self, path: PathType = None):
676675
path = normalize_storage_path(path)
677676
if path:
678677
try:
@@ -687,7 +686,7 @@ def rmdir(self, path: Path = None):
687686
# clear out root
688687
self.root = self.cls()
689688

690-
def getsize(self, path: Path = None):
689+
def getsize(self, path: PathType = None):
691690
path = normalize_storage_path(path)
692691

693692
# obtain value to return size of

0 commit comments

Comments
 (0)