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,

0 commit comments

Comments
 (0)