Skip to content

Commit c31a785

Browse files
Enable some ruff rules (RUF) and fix issues (#1869)
* Enable some ruff rules (RUF) * Apply ruff rule RUF010 RUF010 Use explicit conversion flag * Apply ruff rule RUF019 RUF019 Unnecessary key check before dictionary access * Apply ruff rule RUF100 RUF100 Unused `noqa` directive
1 parent 5a39ff6 commit c31a785

File tree

15 files changed

+33
-21
lines changed

15 files changed

+33
-21
lines changed

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ extend-exclude = [
163163
"docs"
164164
]
165165

166+
[tool.ruff.lint]
167+
extend-select = [
168+
"RUF"
169+
]
170+
ignore = [
171+
"RUF003",
172+
"RUF005",
173+
"RUF009",
174+
"RUF012",
175+
"RUF015",
176+
]
177+
166178
[tool.mypy]
167179
python_version = "3.10"
168180
ignore_missing_imports = true

src/zarr/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from typing import Union
44

55
import zarr.codecs # noqa: F401
6-
from zarr.array import Array, AsyncArray # noqa: F401
6+
from zarr.array import Array, AsyncArray
77
from zarr.array_v2 import ArrayV2
88
from zarr.config import config # noqa: F401
9-
from zarr.group import AsyncGroup, Group # noqa: F401
10-
from zarr.store import ( # noqa: F401
9+
from zarr.group import AsyncGroup, Group
10+
from zarr.store import (
1111
StoreLike,
1212
make_store_path,
1313
)

src/zarr/codecs/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def from_list(cls, codecs: List[Codec]) -> CodecPipeline:
9393
array_array_codecs=tuple(
9494
codec for codec in codecs if isinstance(codec, ArrayArrayCodec)
9595
),
96-
array_bytes_codec=[codec for codec in codecs if isinstance(codec, ArrayBytesCodec)][0],
96+
array_bytes_codec=next(codec for codec in codecs if isinstance(codec, ArrayBytesCodec)),
9797
bytes_bytes_codecs=tuple(
9898
codec for codec in codecs if isinstance(codec, BytesBytesCodec)
9999
),

src/zarr/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def parse_enum(data: JSON, cls: Type[E]) -> E:
8181
raise TypeError(f"Expected str, got {type(data)}")
8282
if data in enum_names(cls):
8383
return cls(data)
84-
raise ValueError(f"Value must be one of {repr(list(enum_names(cls)))}. Got {data} instead.")
84+
raise ValueError(f"Value must be one of {list(enum_names(cls))!r}. Got {data} instead.")
8585

8686

8787
@dataclass(frozen=True)

src/zarr/store/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __str__(self) -> str:
4848
return _dereference_path(str(self.store), self.path)
4949

5050
def __repr__(self) -> str:
51-
return f"StorePath({self.store.__class__.__name__}, {repr(str(self))})"
51+
return f"StorePath({self.store.__class__.__name__}, {str(self)!r})"
5252

5353
def __eq__(self, other: Any) -> bool:
5454
try:

src/zarr/store/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __str__(self) -> str:
8383
return f"file://{self.root}"
8484

8585
def __repr__(self) -> str:
86-
return f"LocalStore({repr(str(self))})"
86+
return f"LocalStore({str(self)!r})"
8787

8888
def __eq__(self, other: object) -> bool:
8989
return isinstance(other, type(self)) and self.root == other.root

src/zarr/store/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __str__(self) -> str:
2323
return f"memory://{id(self._store_dict)}"
2424

2525
def __repr__(self) -> str:
26-
return f"MemoryStore({repr(str(self))})"
26+
return f"MemoryStore({str(self)!r})"
2727

2828
async def get(
2929
self, key: str, byte_range: Optional[Tuple[int, Optional[int]]] = None

src/zarr/store/remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __str__(self) -> str:
3939
return str(self.root)
4040

4141
def __repr__(self) -> str:
42-
return f"RemoteStore({repr(str(self))})"
42+
return f"RemoteStore({str(self)!r})"
4343

4444
def _make_fs(self) -> Tuple[AsyncFileSystem, str]:
4545
import fsspec

src/zarr/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def sync(
8484
if len(unfinished) > 0:
8585
raise asyncio.TimeoutError(f"Coroutine {coro} failed to finish in within {timeout}s")
8686
assert len(finished) == 1
87-
return_result = list(finished)[0].result()
87+
return_result = next(iter(finished)).result()
8888

8989
if isinstance(return_result, BaseException):
9090
raise return_result

src/zarr/v2/_storage/absstore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ABSStore(Store):
5858
-----
5959
In order to use this store, you must install the Microsoft Azure Storage SDK for Python,
6060
``azure-storage-blob>=12.5.0``.
61-
""" # noqa: E501
61+
"""
6262

6363
def __init__(
6464
self,

src/zarr/v2/meta.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,37 @@
3636
def get_extended_dtype_info(dtype) -> dict:
3737
if dtype.str in _v3_complex_types:
3838
return dict(
39-
extension="https://zarr-specs.readthedocs.io/en/core-protocol-v3.0-dev/protocol/extensions/complex-dtypes/v1.0.html", # noqa
39+
extension="https://zarr-specs.readthedocs.io/en/core-protocol-v3.0-dev/protocol/extensions/complex-dtypes/v1.0.html",
4040
type=dtype.str,
4141
fallback=None,
4242
)
4343
elif dtype.str == "|O":
4444
return dict(
45-
extension="TODO: object array protocol URL", # noqa
45+
extension="TODO: object array protocol URL",
4646
type=dtype.str,
4747
fallback=None,
4848
)
4949
elif dtype.str.startswith("|S"):
5050
return dict(
51-
extension="TODO: bytestring array protocol URL", # noqa
51+
extension="TODO: bytestring array protocol URL",
5252
type=dtype.str,
5353
fallback=None,
5454
)
5555
elif dtype.str.startswith("<U") or dtype.str.startswith(">U"):
5656
return dict(
57-
extension="TODO: unicode array protocol URL", # noqa
57+
extension="TODO: unicode array protocol URL",
5858
type=dtype.str,
5959
fallback=None,
6060
)
6161
elif dtype.str.startswith("|V"):
6262
return dict(
63-
extension="TODO: structured array protocol URL", # noqa
63+
extension="TODO: structured array protocol URL",
6464
type=dtype.descr,
6565
fallback=None,
6666
)
6767
elif dtype.str in _v3_datetime_types:
6868
return dict(
69-
extension="https://zarr-specs.readthedocs.io/en/latest/extensions/data-types/datetime/v1.0.html", # noqa
69+
extension="https://zarr-specs.readthedocs.io/en/latest/extensions/data-types/datetime/v1.0.html",
7070
type=dtype.str,
7171
fallback=None,
7272
)

src/zarr/v2/n5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def compressor_config_to_zarr(compressor_config: Dict[str, Any]) -> Optional[Dic
764764
zarr_config["filters"] = None
765765

766766
elif codec_id == "gzip":
767-
if "useZlib" in compressor_config and compressor_config["useZlib"]:
767+
if compressor_config.get("useZlib"):
768768
zarr_config["id"] = "zlib"
769769
zarr_config["level"] = compressor_config["level"]
770770
else:

src/zarr/v2/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def __len__(self):
631631
return len(self._mutable_mapping)
632632

633633
def __repr__(self):
634-
return f"<{self.__class__.__name__}: \n{repr(self._mutable_mapping)}\n at {hex(id(self))}>"
634+
return f"<{self.__class__.__name__}: \n{self._mutable_mapping!r}\n at {hex(id(self))}>"
635635

636636
def __eq__(self, other):
637637
if isinstance(other, KVStore):

tests/v2/test_storage_v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
# from .test_storage import TestSQLiteStore as _TestSQLiteStore
6666
# from .test_storage import TestSQLiteStoreInMemory as _TestSQLiteStoreInMemory
6767
# from .test_storage import TestZipStore as _TestZipStore
68-
# from .test_storage import dimension_separator_fixture, s3, skip_if_nested_chunks # noqa
68+
# from .test_storage import dimension_separator_fixture, s3, skip_if_nested_chunks
6969

7070

7171
# pytestmark = pytest.mark.skipif(not v3_api_available, reason="v3 api is not available")

tests/v2/test_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from zarr.v2.sync import ProcessSynchronizer, ThreadSynchronizer
1717

1818
# zarr_version fixture must be imported although not used directly here
19-
from .test_attrs import TestAttributes # noqa
19+
from .test_attrs import TestAttributes
2020
from .test_core import TestArray
2121
from .test_hierarchy import TestGroup
2222

0 commit comments

Comments
 (0)