Skip to content

Commit 62237fb

Browse files
Apply ruff/flake8-simplify rule SIM118
SIM118 Use `key not in dict` instead of `key not in dict.keys()`
1 parent 3677875 commit 62237fb

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

src/zarr/core/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def parse_zarr_format(data: Any) -> ZarrFormat:
5454
def parse_attributes(data: Any) -> dict[str, Any]:
5555
if data is None:
5656
return {}
57-
elif isinstance(data, dict) and all(isinstance(v, str) for v in data.keys()):
57+
elif isinstance(data, dict) and all(isinstance(k, str) for k in data):
5858
return data
5959
msg = f"Expected dict with string keys. Got {type(data)} instead."
6060
raise TypeError(msg)

src/zarr/registry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def fully_qualified_name(cls: type) -> str:
107107

108108

109109
def register_codec(key: str, codec_cls: type[Codec]) -> None:
110-
if key not in __codec_registries.keys():
110+
if key not in __codec_registries:
111111
__codec_registries[key] = Registry()
112112
__codec_registries[key].register(codec_cls)
113113

@@ -158,7 +158,7 @@ def get_pipeline_class(reload_config: bool = False) -> type[CodecPipeline]:
158158
if pipeline_class:
159159
return pipeline_class
160160
raise BadConfigError(
161-
f"Pipeline class '{path}' not found in registered pipelines: {list(__pipeline_registry.keys())}."
161+
f"Pipeline class '{path}' not found in registered pipelines: {list(__pipeline_registry)}."
162162
)
163163

164164

@@ -172,7 +172,7 @@ def get_buffer_class(reload_config: bool = False) -> type[Buffer]:
172172
if buffer_class:
173173
return buffer_class
174174
raise BadConfigError(
175-
f"Buffer class '{path}' not found in registered buffers: {list(__buffer_registry.keys())}."
175+
f"Buffer class '{path}' not found in registered buffers: {list(__buffer_registry)}."
176176
)
177177

178178

@@ -185,7 +185,7 @@ def get_ndbuffer_class(reload_config: bool = False) -> type[NDBuffer]:
185185
if ndbuffer_class:
186186
return ndbuffer_class
187187
raise BadConfigError(
188-
f"NDBuffer class '{path}' not found in registered buffers: {list(__ndbuffer_registry.keys())}."
188+
f"NDBuffer class '{path}' not found in registered buffers: {list(__ndbuffer_registry)}."
189189
)
190190

191191

src/zarr/store/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
137137
prefix = prefix[:-1]
138138

139139
if prefix == "":
140-
keys_unique = set(k.split("/")[0] for k in self._store_dict.keys())
140+
keys_unique = set(k.split("/")[0] for k in self._store_dict)
141141
else:
142142
# Our dictionary doesn't contain directory markers, but we want to include
143143
# a pseudo directory when there's a nested item and we're listing an

tests/v3/test_store/test_stateful_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get(self, key: str, data: DataObject) -> None:
131131
@rule(key=paths, data=st.data())
132132
def get_invalid_keys(self, key: str, data: DataObject) -> None:
133133
note("(get_invalid)")
134-
assume(key not in self.model.keys())
134+
assume(key not in self.model)
135135
assert self.store.get(key, self.prototype) is None
136136

137137
@precondition(lambda self: len(self.model.keys()) > 0)

0 commit comments

Comments
 (0)