Skip to content

Commit f6c3836

Browse files
Apply ruff preview rule RUF036
RUF036 `None` not at the end of the type annotation. The `None` literal represents the absence of a value. For readability, it's preferred to write the more informative type expressions first.
1 parent 90b3aea commit f6c3836

File tree

12 files changed

+21
-21
lines changed

12 files changed

+21
-21
lines changed

src/zarr/core/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ async def _create_v2(
604604
dtype: npt.DTypeLike,
605605
chunks: ChunkCoords,
606606
dimension_separator: Literal[".", "/"] | None = None,
607-
fill_value: None | float = None,
607+
fill_value: float | None = None,
608608
order: MemoryOrder | None = None,
609609
filters: list[dict[str, JSON]] | None = None,
610610
compressor: dict[str, JSON] | None = None,

src/zarr/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
ChunkCoordsLike = Iterable[int]
3737
ZarrFormat = Literal[2, 3]
3838
NodeType = Literal["array", "group"]
39-
JSON = None | str | int | float | Mapping[str, "JSON"] | tuple["JSON", ...]
39+
JSON = str | int | float | Mapping[str, "JSON"] | tuple["JSON", ...] | None
4040
MemoryOrder = Literal["C", "F"]
4141
AccessModeLiteral = Literal["r", "r+", "a", "w", "w-"]
4242

src/zarr/core/metadata/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from zarr.core.common import JSON
77

88

9-
def parse_attributes(data: None | dict[str, JSON]) -> dict[str, JSON]:
9+
def parse_attributes(data: dict[str, JSON] | None) -> dict[str, JSON]:
1010
if data is None:
1111
return {}
1212

src/zarr/core/metadata/v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ArrayV2Metadata(Metadata):
4444
shape: ChunkCoords
4545
chunks: tuple[int, ...]
4646
dtype: np.dtype[Any]
47-
fill_value: None | int | float | str | bytes = 0
47+
fill_value: int | float | str | bytes | None = 0
4848
order: MemoryOrder = "C"
4949
filters: tuple[numcodecs.abc.Codec, ...] | None = None
5050
dimension_separator: Literal[".", "/"] = "."

src/zarr/core/metadata/v3.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ def __init__(
225225
chunk_key_encoding: dict[str, JSON] | ChunkKeyEncoding,
226226
fill_value: Any,
227227
codecs: Iterable[Codec | dict[str, JSON]],
228-
attributes: None | dict[str, JSON],
229-
dimension_names: None | Iterable[str],
230-
storage_transformers: None | Iterable[dict[str, JSON]] = None,
228+
attributes: dict[str, JSON] | None,
229+
dimension_names: Iterable[str] | None,
230+
storage_transformers: Iterable[dict[str, JSON]] | None = None,
231231
) -> None:
232232
"""
233233
Because the class is a frozen dataclass, we set attributes using object.__setattr__
@@ -540,7 +540,7 @@ class DataType(Enum):
540540
bytes = "bytes"
541541

542542
@property
543-
def byte_count(self) -> None | int:
543+
def byte_count(self) -> int | None:
544544
data_type_byte_counts = {
545545
DataType.bool: 1,
546546
DataType.int8: 1,
@@ -626,7 +626,7 @@ def from_numpy(cls, dtype: np.dtype[Any]) -> DataType:
626626
return DataType[dtype_to_data_type[dtype.str]]
627627

628628
@classmethod
629-
def parse(cls, dtype: None | DataType | Any) -> DataType:
629+
def parse(cls, dtype: DataType | Any | None) -> DataType:
630630
if dtype is None:
631631
return DataType[DEFAULT_DTYPE]
632632
if isinstance(dtype, DataType):

src/zarr/storage/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def normalize_path(path: str | bytes | Path | None) -> str:
4545

4646

4747
def _normalize_interval_index(
48-
data: Buffer, interval: None | tuple[int | None, int | None]
48+
data: Buffer, interval: tuple[int | None, int | None] | None
4949
) -> tuple[int, int]:
5050
"""
5151
Convert an implicit interval into an explicit start and length

src/zarr/testing/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_store_supports_listing(self, store: S) -> None:
106106
@pytest.mark.parametrize("data", [b"\x01\x02\x03\x04", b""])
107107
@pytest.mark.parametrize("byte_range", [None, (0, None), (1, None), (1, 2), (None, 1)])
108108
async def test_get(
109-
self, store: S, key: str, data: bytes, byte_range: None | tuple[int | None, int | None]
109+
self, store: S, key: str, data: bytes, byte_range: tuple[int | None, int | None] | None
110110
) -> None:
111111
"""
112112
Ensure that data can be read from the store using the store.get method.

src/zarr/testing/strategies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def arrays(
117117
shapes: st.SearchStrategy[tuple[int, ...]] = array_shapes,
118118
compressors: st.SearchStrategy = compressors,
119119
stores: st.SearchStrategy[StoreLike] = stores,
120-
paths: st.SearchStrategy[None | str] = paths,
120+
paths: st.SearchStrategy[str | None] = paths,
121121
array_names: st.SearchStrategy = array_names,
122122
arrays: st.SearchStrategy | None = None,
123123
attrs: st.SearchStrategy = attrs,

tests/test_codecs/test_vlen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@pytest.mark.parametrize("as_object_array", [False, True])
2626
@pytest.mark.parametrize("codecs", [None, [VLenUTF8Codec()], [VLenUTF8Codec(), ZstdCodec()]])
2727
def test_vlen_string(
28-
store: Store, dtype: None | np.dtype[Any], as_object_array: bool, codecs: None | list[Codec]
28+
store: Store, dtype: np.dtype[Any] | None, as_object_array: bool, codecs: list[Codec] | None
2929
) -> None:
3030
strings = ["hello", "world", "this", "is", "a", "test"]
3131
data = np.array(strings, dtype=dtype).reshape((2, 3))
@@ -62,7 +62,7 @@ def test_vlen_string(
6262
@pytest.mark.parametrize("store", ["memory", "local"], indirect=["store"])
6363
@pytest.mark.parametrize("as_object_array", [False, True])
6464
@pytest.mark.parametrize("codecs", [None, [VLenBytesCodec()], [VLenBytesCodec(), ZstdCodec()]])
65-
def test_vlen_bytes(store: Store, as_object_array: bool, codecs: None | list[Codec]) -> None:
65+
def test_vlen_bytes(store: Store, as_object_array: bool, codecs: list[Codec] | None) -> None:
6666
bstrings = [b"hello", b"world", b"this", b"is", b"a", b"test"]
6767
data = np.array(bstrings).reshape((2, 3))
6868
assert data.dtype == "|S5"

tests/test_metadata/test_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_metadata_to_dict(
4343
fill_value: Any,
4444
order: Literal["C", "F"],
4545
dimension_separator: Literal[".", "/"] | None,
46-
attributes: None | dict[str, Any],
46+
attributes: dict[str, Any] | None,
4747
) -> None:
4848
shape = (1, 2, 3)
4949
chunks = (1,) * len(shape)

tests/test_metadata/test_v3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ def test_metadata_to_dict(
240240
chunk_key_encoding: Literal["v2", "default"],
241241
dimension_separator: Literal[".", "/"] | None,
242242
dimension_names: Literal["nones", "strings", "missing"],
243-
attributes: None | dict[str, Any],
244-
storage_transformers: None | tuple[dict[str, JSON]],
243+
attributes: dict[str, Any] | None,
244+
storage_transformers: tuple[dict[str, JSON]] | None,
245245
) -> None:
246246
shape = (1, 2, 3)
247247
data_type = DataType.uint8

tests/test_store/test_memory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ async def get(self, store: MemoryStore, key: str) -> Buffer:
2121
@pytest.fixture(params=[None, True])
2222
def store_kwargs(
2323
self, request: pytest.FixtureRequest
24-
) -> dict[str, str | None | dict[str, Buffer]]:
24+
) -> dict[str, str | dict[str, Buffer] | None]:
2525
kwargs = {"store_dict": None}
2626
if request.param is True:
2727
kwargs["store_dict"] = {}
2828
return kwargs
2929

3030
@pytest.fixture
31-
def store(self, store_kwargs: str | None | dict[str, Buffer]) -> MemoryStore:
31+
def store(self, store_kwargs: str | dict[str, Buffer] | None) -> MemoryStore:
3232
return self.store_cls(**store_kwargs)
3333

3434
def test_store_repr(self, store: MemoryStore) -> None:
@@ -61,14 +61,14 @@ async def get(self, store: MemoryStore, key: str) -> Buffer:
6161
@pytest.fixture(params=[None, True])
6262
def store_kwargs(
6363
self, request: pytest.FixtureRequest
64-
) -> dict[str, str | None | dict[str, Buffer]]:
64+
) -> dict[str, str | dict[str, Buffer] | None]:
6565
kwargs = {"store_dict": None}
6666
if request.param is True:
6767
kwargs["store_dict"] = {}
6868
return kwargs
6969

7070
@pytest.fixture
71-
def store(self, store_kwargs: str | None | dict[str, gpu.Buffer]) -> GpuMemoryStore:
71+
def store(self, store_kwargs: str | dict[str, gpu.Buffer] | None) -> GpuMemoryStore:
7272
return self.store_cls(**store_kwargs)
7373

7474
def test_store_repr(self, store: GpuMemoryStore) -> None:

0 commit comments

Comments
 (0)