Skip to content

Commit 7a442e1

Browse files
committed
Use explicit json encoder args
1 parent 4bac97d commit 7a442e1

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/zarr/core/metadata/v3.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,30 @@ def parse_storage_transformers(data: object) -> tuple[dict[str, JSON], ...]:
134134

135135

136136
class V3JsonEncoder(json.JSONEncoder):
137-
def __init__(self, *args: Any, **kwargs: Any) -> None:
138-
super().__init__(*args, **kwargs)
139-
self.indent = kwargs.pop("indent") or config.get("json_indent")
137+
def __init__(
138+
self,
139+
*,
140+
skipkeys=False,
141+
ensure_ascii=True,
142+
check_circular=True,
143+
allow_nan=True,
144+
sort_keys=False,
145+
indent=None,
146+
separators=None,
147+
default=None,
148+
) -> None:
149+
if indent is None:
150+
indent = config.get("json_indent")
151+
super().__init__(
152+
skipkeys=skipkeys,
153+
ensure_ascii=ensure_ascii,
154+
check_circular=check_circular,
155+
allow_nan=allow_nan,
156+
sort_keys=sort_keys,
157+
indent=indent,
158+
separators=separators,
159+
default=default,
160+
)
140161

141162
def default(self, o: object) -> Any:
142163
if isinstance(o, np.dtype):

tests/test_metadata/test_v3.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,7 @@ def test_json_indent(indent: int):
310310
with config.set({"json_indent": indent}):
311311
m = GroupMetadata()
312312
d = m.to_buffer_dict(default_buffer_prototype())["zarr.json"].to_bytes()
313-
314-
class TestIndentEncoder(json.JSONEncoder):
315-
def __init__(self, *args: Any, **kwargs: Any) -> None:
316-
super().__init__(*args, **kwargs)
317-
self.indent = indent
318-
319-
# using json.JSONEncoder adds an extra ' ' on each line
320-
# compared with json.dumps(json.loads(d), indent=2)...
321-
expected = json.dumps(json.loads(d), cls=TestIndentEncoder).encode()
322-
assert d == expected
323-
# ...but we can check that None really removes indent.
324-
if indent is None:
325-
assert d == json.dumps(json.loads(d), indent=indent).encode()
313+
assert d == json.dumps(json.loads(d), indent=indent).encode()
326314

327315

328316
# @pytest.mark.parametrize("fill_value", [-1, 0, 1, 2932897])

0 commit comments

Comments
 (0)