Skip to content

Commit ea76ec8

Browse files
stibrewd-v-b
andauthored
fix: copy attributes passed from the user to avoid mutation (#4060)
* fix: copy attributes passed from the user to avoid mutation * fix: copy attributes passed from the user to avoid mutation --------- Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
1 parent 3d8746a commit ea76ec8

3 files changed

Lines changed: 3 additions & 2 deletions

File tree

changes/4059.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevents mutation of the attributes dict provided by the user by copying them instead of keeping the reference

src/zarr/core/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def parse_attributes(data: Any) -> dict[str, Any]:
105105
if data is None:
106106
return {}
107107
elif isinstance(data, dict) and all(isinstance(k, str) for k in data):
108-
return data
108+
return dict(data)
109109
msg = f"Expected dict with string keys. Got {type(data)} instead."
110110
raise TypeError(msg)
111111

src/zarr/core/metadata/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ def parse_attributes(data: dict[str, JSON] | None) -> dict[str, JSON]:
1010
if data is None:
1111
return {}
1212

13-
return data
13+
return dict(data)

0 commit comments

Comments
 (0)