Skip to content

Commit f95a7ac

Browse files
Apply ruff/tryceratops rule TRY300
TRY300 Consider moving this statement to an `else` block
1 parent e64157c commit f95a7ac

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

src/zarr/group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,10 @@ async def contains(self, member: str) -> bool:
467467
# TODO: this can be made more efficient.
468468
try:
469469
await self.getitem(member)
470-
return True
471470
except KeyError:
472471
return False
472+
else:
473+
return True
473474

474475
# todo: decide if this method should be separate from `groups`
475476
async def group_keys(self) -> AsyncGenerator[str, None]:

src/zarr/store/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,10 @@ async def contains_group(store_path: StorePath, zarr_format: ZarrFormat) -> bool
251251
extant_meta_json = json.loads(extant_meta_bytes.to_bytes())
252252
# we avoid constructing a full metadata document here in the name of speed.
253253
result: bool = extant_meta_json["node_type"] == "group"
254-
return result
255254
except (ValueError, KeyError):
256255
return False
256+
else:
257+
return result
257258
elif zarr_format == 2:
258259
return await (store_path / ZGROUP_JSON).exists()
259260
msg = f"Invalid zarr_format provided. Got {zarr_format}, expected 2 or 3" # type: ignore[unreachable]

src/zarr/store/local.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ async def clear(self) -> None:
8787
async def empty(self) -> bool:
8888
try:
8989
subpaths = os.listdir(self.root)
90-
return not subpaths
9190
except FileNotFoundError:
9291
return True
92+
else:
93+
return not subpaths
9394

9495
def __str__(self) -> str:
9596
return f"file://{self.root}"

src/zarr/store/remote.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ async def get(
118118
else self._fs._cat_file(path)
119119
)
120120
)
121-
return value
122121

123122
except self.allowed_exceptions:
124123
return None
@@ -127,6 +126,8 @@ async def get(
127126
# this is an s3-specific condition we probably don't want to leak
128127
return prototype.buffer.from_bytes(b"")
129128
raise
129+
else:
130+
return value
130131

131132
async def set(
132133
self,

0 commit comments

Comments
 (0)