Skip to content

Commit 50b3fb1

Browse files
Enable ruff/flake8-implicit-str-concat rules (ISC) and fix issues (#1868)
* Enable ruff/flake8-implicit-str-concat rules (ISC) * Apply ruff/flake8-implicit-str-concat rule ISC001 ISC001 Implicitly concatenated string literals on one line * A round of formatting after linting * Aplly ruff/flake8-implicit-str-concat rule ISC003 ISC003 Explicitly concatenated string should be implicitly concatenated --------- Co-authored-by: Joe Hamman <joe@earthmover.io>
1 parent 88946d2 commit 50b3fb1

File tree

9 files changed

+23
-39
lines changed

9 files changed

+23
-39
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ extend-exclude = [
169169
extend-select = [
170170
"B", # flake8-bugbear
171171
"I", # isort
172+
"ISC",
172173
"UP", # pyupgrade
173174
"RSE",
174175
"RUF",

src/zarr/codecs/crc32c_.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ async def decode_single(
4242
stored_checksum = bytes(crc32_bytes)
4343
if computed_checksum != stored_checksum:
4444
raise ValueError(
45-
"Stored and computed checksum do not match. "
46-
+ f"Stored: {stored_checksum!r}. Computed: {computed_checksum!r}."
45+
f"Stored and computed checksum do not match. Stored: {stored_checksum!r}. Computed: {computed_checksum!r}."
4746
)
4847
return Buffer.from_array_like(inner_bytes)
4948

src/zarr/codecs/pipeline.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,31 +104,26 @@ def codecs_from_list(
104104
if prev_codec is not None:
105105
if isinstance(codec, ArrayBytesCodec) and isinstance(prev_codec, ArrayBytesCodec):
106106
raise ValueError(
107-
f"ArrayBytesCodec '{type(codec)}' cannot follow after "
108-
+ f"ArrayBytesCodec '{type(prev_codec)}' because exactly "
109-
+ "1 ArrayBytesCodec is allowed."
107+
f"ArrayBytesCodec '{type(codec)}' cannot follow after ArrayBytesCodec '{type(prev_codec)}' because exactly 1 ArrayBytesCodec is allowed."
110108
)
111109
if isinstance(codec, ArrayBytesCodec) and isinstance(prev_codec, BytesBytesCodec):
112110
raise ValueError(
113-
f"ArrayBytesCodec '{type(codec)}' cannot follow after "
114-
+ f"BytesBytesCodec '{type(prev_codec)}'."
111+
f"ArrayBytesCodec '{type(codec)}' cannot follow after BytesBytesCodec '{type(prev_codec)}'."
115112
)
116113
if isinstance(codec, ArrayArrayCodec) and isinstance(prev_codec, ArrayBytesCodec):
117114
raise ValueError(
118-
f"ArrayArrayCodec '{type(codec)}' cannot follow after "
119-
+ f"ArrayBytesCodec '{type(prev_codec)}'."
115+
f"ArrayArrayCodec '{type(codec)}' cannot follow after ArrayBytesCodec '{type(prev_codec)}'."
120116
)
121117
if isinstance(codec, ArrayArrayCodec) and isinstance(prev_codec, BytesBytesCodec):
122118
raise ValueError(
123-
f"ArrayArrayCodec '{type(codec)}' cannot follow after "
124-
+ f"BytesBytesCodec '{type(prev_codec)}'."
119+
f"ArrayArrayCodec '{type(codec)}' cannot follow after BytesBytesCodec '{type(prev_codec)}'."
125120
)
126121
prev_codec = codec
127122

128123
if any(isinstance(codec, ShardingCodec) for codec in codecs) and len(codecs) > 1:
129124
warn(
130125
"Combining a `sharding_indexed` codec disables partial reads and "
131-
+ "writes, which may lead to inefficient performance.",
126+
"writes, which may lead to inefficient performance.",
132127
stacklevel=3,
133128
)
134129

src/zarr/codecs/sharding.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ def evolve(self, array_spec: ArraySpec) -> Self:
361361
def validate(self, array_metadata: ArrayMetadata) -> None:
362362
if len(self.chunk_shape) != array_metadata.ndim:
363363
raise ValueError(
364-
"The shard's `chunk_shape` and array's `shape` need to have the "
365-
+ "same number of dimensions."
364+
"The shard's `chunk_shape` and array's `shape` need to have the same number of dimensions."
366365
)
367366
if not isinstance(array_metadata.chunk_grid, RegularChunkGrid):
368367
raise ValueError("Sharding is only compatible with regular chunk grids.")
@@ -375,8 +374,7 @@ def validate(self, array_metadata: ArrayMetadata) -> None:
375374
)
376375
):
377376
raise ValueError(
378-
"The array's `chunk_shape` needs to be divisible by the "
379-
+ "shard's inner `chunk_shape`."
377+
"The array's `chunk_shape` needs to be divisible by the shard's inner `chunk_shape`."
380378
)
381379

382380
async def decode_single(

src/zarr/codecs/transpose.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,15 @@ def to_dict(self) -> dict[str, JSON]:
4545
def evolve(self, array_spec: ArraySpec) -> Self:
4646
if len(self.order) != array_spec.ndim:
4747
raise ValueError(
48-
"The `order` tuple needs have as many entries as "
49-
+ f"there are dimensions in the array. Got {self.order}."
48+
f"The `order` tuple needs have as many entries as there are dimensions in the array. Got {self.order}."
5049
)
5150
if len(self.order) != len(set(self.order)):
5251
raise ValueError(
5352
f"There must not be duplicates in the `order` tuple. Got {self.order}."
5453
)
5554
if not all(0 <= x < array_spec.ndim for x in self.order):
5655
raise ValueError(
57-
"All entries in the `order` tuple must be between 0 and "
58-
+ f"the number of dimensions in the array. Got {self.order}."
56+
f"All entries in the `order` tuple must be between 0 and the number of dimensions in the array. Got {self.order}."
5957
)
6058
order = tuple(self.order)
6159

src/zarr/store/remote.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ def __init__(self, url: UPath | str, **storage_options: dict[str, Any]):
2525
if isinstance(url, str):
2626
self.root = UPath(url, **storage_options)
2727
else:
28-
assert len(storage_options) == 0, (
29-
"If constructed with a UPath object, no additional "
30-
+ "storage_options are allowed."
31-
)
28+
assert (
29+
len(storage_options) == 0
30+
), "If constructed with a UPath object, no additional storage_options are allowed."
3231
self.root = url.rstrip("/")
3332
# test instantiate file system
3433
fs, _ = fsspec.core.url_to_fs(str(self.root), asynchronous=True, **self.root._kwargs)

src/zarr/v2/convenience.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def __init__(self, log):
470470
self.log_file = log
471471
else:
472472
raise TypeError(
473-
"log must be a callable function, file path or " "file-like object, found %r" % log
473+
"log must be a callable function, file path or file-like object, found %r" % log
474474
)
475475

476476
def __enter__(self):
@@ -898,7 +898,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
898898
if exists:
899899
if if_exists == "raise":
900900
raise CopyError(
901-
"an object {!r} already exists in destination " "{!r}".format(name, dest.name)
901+
"an object {!r} already exists in destination {!r}".format(name, dest.name)
902902
)
903903
elif if_exists == "skip":
904904
do_copy = False
@@ -990,7 +990,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
990990
if exists_array:
991991
if if_exists == "raise":
992992
raise CopyError(
993-
"an array {!r} already exists in destination " "{!r}".format(name, dest.name)
993+
"an array {!r} already exists in destination {!r}".format(name, dest.name)
994994
)
995995
elif if_exists == "skip":
996996
do_copy = False

src/zarr/v2/indexing.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,12 @@ class BoolArrayDimIndexer:
363363
def __init__(self, dim_sel, dim_len, dim_chunk_len):
364364
# check number of dimensions
365365
if not is_bool_array(dim_sel, 1):
366-
raise IndexError(
367-
"Boolean arrays in an orthogonal selection must " "be 1-dimensional only"
368-
)
366+
raise IndexError("Boolean arrays in an orthogonal selection must be 1-dimensional only")
369367

370368
# check shape
371369
if dim_sel.shape[0] != dim_len:
372370
raise IndexError(
373-
"Boolean array has the wrong length for dimension; " "expected {}, got {}".format(
371+
"Boolean array has the wrong length for dimension; expected {}, got {}".format(
374372
dim_len, dim_sel.shape[0]
375373
)
376374
)
@@ -464,9 +462,7 @@ def __init__(
464462
# ensure 1d array
465463
dim_sel = np.asanyarray(dim_sel)
466464
if not is_integer_array(dim_sel, 1):
467-
raise IndexError(
468-
"integer arrays in an orthogonal selection must be " "1-dimensional only"
469-
)
465+
raise IndexError("integer arrays in an orthogonal selection must be 1-dimensional only")
470466

471467
# handle wraparound
472468
if wraparound:
@@ -920,9 +916,7 @@ def check_fields(fields, dtype):
920916
# check type
921917
if not isinstance(fields, (str, list, tuple)):
922918
raise IndexError(
923-
"'fields' argument must be a string or list of strings; found " "{!r}".format(
924-
type(fields)
925-
)
919+
"'fields' argument must be a string or list of strings; found {!r}".format(type(fields))
926920
)
927921
if fields:
928922
if dtype.names is None:

src/zarr/v2/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def normalize_fill_value(fill_value, dtype: np.dtype[Any]):
307307

308308
if not isinstance(fill_value, str):
309309
raise ValueError(
310-
"fill_value {!r} is not valid for dtype {}; must be a " "unicode string".format(
310+
"fill_value {!r} is not valid for dtype {}; must be a unicode string".format(
311311
fill_value, dtype
312312
)
313313
)
@@ -323,7 +323,7 @@ def normalize_fill_value(fill_value, dtype: np.dtype[Any]):
323323
except Exception as e:
324324
# re-raise with our own error message to be helpful
325325
raise ValueError(
326-
"fill_value {!r} is not valid for dtype {}; nested " "exception: {}".format(
326+
"fill_value {!r} is not valid for dtype {}; nested exception: {}".format(
327327
fill_value, dtype, e
328328
)
329329
)

0 commit comments

Comments
 (0)