Skip to content

Commit 2d0175a

Browse files
Apply ruff/Pylint preview rule PLR6201
PLR6201 Use a set literal when testing for membership
1 parent a014610 commit 2d0175a

File tree

11 files changed

+17
-17
lines changed

11 files changed

+17
-17
lines changed

src/zarr/core/chunk_key_encodings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
def parse_separator(data: JSON) -> SeparatorLiteral:
21-
if data not in (".", "/"):
21+
if data not in {".", "/"}:
2222
raise ValueError(f"Expected an '.' or '/' separator. Got {data} instead.")
2323
return cast("SeparatorLiteral", data)
2424

src/zarr/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def parse_fill_value(data: Any) -> Any:
157157

158158

159159
def parse_order(data: Any) -> Literal["C", "F"]:
160-
if data in ("C", "F"):
160+
if data in {"C", "F"}:
161161
return cast("Literal['C', 'F']", data)
162162
raise ValueError(f"Expected one of ('C', 'F'), got {data} instead.")
163163

src/zarr/core/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def enable_gpu(self) -> ConfigSet:
133133

134134

135135
def parse_indexing_order(data: Any) -> Literal["C", "F"]:
136-
if data in ("C", "F"):
136+
if data in {"C", "F"}:
137137
return cast("Literal['C', 'F']", data)
138138
msg = f"Expected one of ('C', 'F'), got {data} instead."
139139
raise ValueError(msg)

src/zarr/core/group.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@
8181

8282
def parse_zarr_format(data: Any) -> ZarrFormat:
8383
"""Parse the zarr_format field from metadata."""
84-
if data in (2, 3):
84+
if data in {2, 3}:
8585
return cast("ZarrFormat", data)
8686
msg = f"Invalid zarr_format. Expected one of 2 or 3. Got {data}."
8787
raise ValueError(msg)
8888

8989

9090
def parse_node_type(data: Any) -> NodeType:
9191
"""Parse the node_type field from metadata."""
92-
if data in ("array", "group"):
92+
if data in {"array", "group"}:
9393
return cast("Literal['array', 'group']", data)
9494
raise MetadataValidationError("node_type", "array or group", data)
9595

@@ -402,7 +402,7 @@ def __init__(
402402
@classmethod
403403
def from_dict(cls, data: dict[str, Any]) -> GroupMetadata:
404404
data = dict(data)
405-
assert data.pop("node_type", None) in ("group", None)
405+
assert data.pop("node_type", None) in {"group", None}
406406
consolidated_metadata = data.pop("consolidated_metadata", None)
407407
if consolidated_metadata:
408408
data["consolidated_metadata"] = ConsolidatedMetadata.from_dict(consolidated_metadata)

src/zarr/core/indexing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def err_too_many_indices(selection: Any, shape: ChunkCoords) -> None:
7777

7878

7979
def _zarr_array_to_int_or_bool_array(arr: Array) -> npt.NDArray[np.intp] | npt.NDArray[np.bool_]:
80-
if arr.dtype.kind in ("i", "b"):
80+
if arr.dtype.kind in {"i", "b"}:
8181
return np.asarray(arr)
8282
else:
8383
raise IndexError(
@@ -184,7 +184,7 @@ def is_integer(x: Any) -> TypeGuard[int]:
184184

185185
def is_bool(x: Any) -> TypeGuard[bool | np.bool_]:
186186
"""True if x is a boolean (both pure Python or NumPy)."""
187-
return type(x) in [bool, np.bool_]
187+
return type(x) in {bool, np.bool_}
188188

189189

190190
def is_integer_list(x: Any) -> TypeGuard[list[int]]:
@@ -422,7 +422,7 @@ def __iter__(self) -> Iterator[ChunkDimProjection]:
422422
dim_out_sel = slice(dim_out_offset, dim_out_offset + dim_chunk_nitems)
423423

424424
is_complete_chunk = (
425-
dim_chunk_sel_start == 0 and (self.stop >= dim_limit) and self.step in [1, None]
425+
dim_chunk_sel_start == 0 and (self.stop >= dim_limit) and self.step in {1, None}
426426
)
427427
yield ChunkDimProjection(dim_chunk_ix, dim_chunk_sel, dim_out_sel, is_complete_chunk)
428428

src/zarr/core/metadata/v3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def parse_fill_value(
527527
np_dtype = cast("np.dtype[Any]", data_type.to_numpy())
528528

529529
if isinstance(fill_value, Sequence) and not isinstance(fill_value, str):
530-
if data_type in (DataType.complex64, DataType.complex128):
530+
if data_type in {DataType.complex64, DataType.complex128}:
531531
if len(fill_value) == 2:
532532
decoded_fill_value = tuple(
533533
SPECIAL_FLOATS_ENCODED.get(value, value) for value in fill_value
@@ -557,7 +557,7 @@ def parse_fill_value(
557557
raise ValueError(f"fill value {fill_value!r} is not valid for dtype {data_type}") from e
558558
# Check if the value is still representable by the dtype
559559
if (fill_value == "NaN" and np.isnan(casted_value)) or (
560-
fill_value in ["Infinity", "-Infinity"] and not np.isfinite(casted_value)
560+
fill_value in {"Infinity", "-Infinity"} and not np.isfinite(casted_value)
561561
):
562562
pass
563563
elif np_dtype.kind == "f":

src/zarr/storage/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ async def make_store_path(
291291
if isinstance(store_like, StorePath):
292292
result = store_like / path_normalized
293293
else:
294-
assert mode in (None, "r", "r+", "a", "w", "w-")
294+
assert mode in {None, "r", "r+", "a", "w", "w-"}
295295
# if mode 'r' was provided, we'll open any new stores as read-only
296296
_read_only = mode == "r"
297297
if isinstance(store_like, Store):

src/zarr/testing/strategies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ def clear_store(x: Store) -> Store:
100100
)
101101
node_names = (
102102
st.text(zarr_key_chars, min_size=1)
103-
.filter(lambda t: t not in (".", "..") and not t.startswith("__"))
103+
.filter(lambda t: t not in {".", ".."} and not t.startswith("__"))
104104
.filter(lambda name: name.lower() != "zarr.json")
105105
)
106106
short_node_names = (
107107
st.text(zarr_key_chars, max_size=3, min_size=1)
108-
.filter(lambda t: t not in (".", "..") and not t.startswith("__"))
108+
.filter(lambda t: t not in {".", ".."} and not t.startswith("__"))
109109
.filter(lambda name: name.lower() != "zarr.json")
110110
)
111111
array_names = node_names

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ async def test_open_falls_back_to_open_group_async(zarr_format: ZarrFormat) -> N
11421142
def test_open_modes_creates_group(tmp_path: pathlib.Path, mode: str) -> None:
11431143
# https://github.com/zarr-developers/zarr-python/issues/2490
11441144
zarr_dir = tmp_path / f"mode-{mode}-test.zarr"
1145-
if mode in ["r", "r+"]:
1145+
if mode in {"r", "r+"}:
11461146
# Expect FileNotFoundError to be raised if 'r' or 'r+' mode
11471147
with pytest.raises(FileNotFoundError):
11481148
zarr.open(store=zarr_dir, mode=mode)

tests/test_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ def _index_array(arr: Array, index: Any) -> Any:
16831683
pytest.param(
16841684
"fork",
16851685
marks=pytest.mark.skipif(
1686-
sys.platform in ("win32", "darwin"), reason="fork not supported on Windows or OSX"
1686+
sys.platform in {"win32", "darwin"}, reason="fork not supported on Windows or OSX"
16871687
),
16881688
),
16891689
"spawn",

0 commit comments

Comments
 (0)