Skip to content

Enable some ruff rules (RUF) and fix issues #1869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ extend-exclude = [
"docs"
]

[tool.ruff.lint]
extend-select = [
"RUF"
]
ignore = [
"RUF003",
"RUF005",
"RUF009",
"RUF012",
"RUF015",
]

[tool.mypy]
python_version = "3.10"
ignore_missing_imports = true
Expand Down
6 changes: 3 additions & 3 deletions src/zarr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from typing import Union

import zarr.codecs # noqa: F401
from zarr.array import Array, AsyncArray # noqa: F401
from zarr.array import Array, AsyncArray
from zarr.array_v2 import ArrayV2
from zarr.config import config # noqa: F401
from zarr.group import AsyncGroup, Group # noqa: F401
from zarr.store import ( # noqa: F401
from zarr.group import AsyncGroup, Group
from zarr.store import (
StoreLike,
make_store_path,
)
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/codecs/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def from_list(cls, codecs: List[Codec]) -> CodecPipeline:
array_array_codecs=tuple(
codec for codec in codecs if isinstance(codec, ArrayArrayCodec)
),
array_bytes_codec=[codec for codec in codecs if isinstance(codec, ArrayBytesCodec)][0],
array_bytes_codec=next(codec for codec in codecs if isinstance(codec, ArrayBytesCodec)),
bytes_bytes_codecs=tuple(
codec for codec in codecs if isinstance(codec, BytesBytesCodec)
),
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def parse_enum(data: JSON, cls: Type[E]) -> E:
raise TypeError(f"Expected str, got {type(data)}")
if data in enum_names(cls):
return cls(data)
raise ValueError(f"Value must be one of {repr(list(enum_names(cls)))}. Got {data} instead.")
raise ValueError(f"Value must be one of {list(enum_names(cls))!r}. Got {data} instead.")


@dataclass(frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/store/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __str__(self) -> str:
return _dereference_path(str(self.store), self.path)

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

def __eq__(self, other: Any) -> bool:
try:
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/store/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __str__(self) -> str:
return f"file://{self.root}"

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

def __eq__(self, other: object) -> bool:
return isinstance(other, type(self)) and self.root == other.root
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/store/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __str__(self) -> str:
return f"memory://{id(self._store_dict)}"

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

async def get(
self, key: str, byte_range: Optional[Tuple[int, Optional[int]]] = None
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/store/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __str__(self) -> str:
return str(self.root)

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

def _make_fs(self) -> Tuple[AsyncFileSystem, str]:
import fsspec
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def sync(
if len(unfinished) > 0:
raise asyncio.TimeoutError(f"Coroutine {coro} failed to finish in within {timeout}s")
assert len(finished) == 1
return_result = list(finished)[0].result()
return_result = next(iter(finished)).result()

if isinstance(return_result, BaseException):
raise return_result
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/v2/_storage/absstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ABSStore(Store):
-----
In order to use this store, you must install the Microsoft Azure Storage SDK for Python,
``azure-storage-blob>=12.5.0``.
""" # noqa: E501
"""

def __init__(
self,
Expand Down
12 changes: 6 additions & 6 deletions src/zarr/v2/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,37 @@
def get_extended_dtype_info(dtype) -> dict:
if dtype.str in _v3_complex_types:
return dict(
extension="https://zarr-specs.readthedocs.io/en/core-protocol-v3.0-dev/protocol/extensions/complex-dtypes/v1.0.html", # noqa
extension="https://zarr-specs.readthedocs.io/en/core-protocol-v3.0-dev/protocol/extensions/complex-dtypes/v1.0.html",
type=dtype.str,
fallback=None,
)
elif dtype.str == "|O":
return dict(
extension="TODO: object array protocol URL", # noqa
extension="TODO: object array protocol URL",
type=dtype.str,
fallback=None,
)
elif dtype.str.startswith("|S"):
return dict(
extension="TODO: bytestring array protocol URL", # noqa
extension="TODO: bytestring array protocol URL",
type=dtype.str,
fallback=None,
)
elif dtype.str.startswith("<U") or dtype.str.startswith(">U"):
return dict(
extension="TODO: unicode array protocol URL", # noqa
extension="TODO: unicode array protocol URL",
type=dtype.str,
fallback=None,
)
elif dtype.str.startswith("|V"):
return dict(
extension="TODO: structured array protocol URL", # noqa
extension="TODO: structured array protocol URL",
type=dtype.descr,
fallback=None,
)
elif dtype.str in _v3_datetime_types:
return dict(
extension="https://zarr-specs.readthedocs.io/en/latest/extensions/data-types/datetime/v1.0.html", # noqa
extension="https://zarr-specs.readthedocs.io/en/latest/extensions/data-types/datetime/v1.0.html",
type=dtype.str,
fallback=None,
)
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/v2/n5.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def compressor_config_to_zarr(compressor_config: Dict[str, Any]) -> Optional[Dic
zarr_config["filters"] = None

elif codec_id == "gzip":
if "useZlib" in compressor_config and compressor_config["useZlib"]:
if compressor_config.get("useZlib"):
zarr_config["id"] = "zlib"
zarr_config["level"] = compressor_config["level"]
else:
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/v2/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def __len__(self):
return len(self._mutable_mapping)

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

def __eq__(self, other):
if isinstance(other, KVStore):
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_storage_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# from .test_storage import TestSQLiteStore as _TestSQLiteStore
# from .test_storage import TestSQLiteStoreInMemory as _TestSQLiteStoreInMemory
# from .test_storage import TestZipStore as _TestZipStore
# from .test_storage import dimension_separator_fixture, s3, skip_if_nested_chunks # noqa
# from .test_storage import dimension_separator_fixture, s3, skip_if_nested_chunks


# pytestmark = pytest.mark.skipif(not v3_api_available, reason="v3 api is not available")
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from zarr.v2.sync import ProcessSynchronizer, ThreadSynchronizer

# zarr_version fixture must be imported although not used directly here
from .test_attrs import TestAttributes # noqa
from .test_attrs import TestAttributes
from .test_core import TestArray
from .test_hierarchy import TestGroup

Expand Down
Loading