mirror of
https://github.com/home-assistant/core.git
synced 2026-12-04 12:50:45 -04:00
Prevent in-place union from modifying ReadOnlyDict (#187625)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
cbbd58b4ca
commit
19253b0418
@@ -20,6 +20,7 @@ class ReadOnlyDict[_KT, _VT](dict[_KT, _VT]):
|
||||
clear = _readonly
|
||||
update = _readonly
|
||||
setdefault = _readonly
|
||||
__ior__ = _readonly
|
||||
|
||||
def __copy__(self) -> dict[_KT, _VT]:
|
||||
"""Create a shallow copy."""
|
||||
|
||||
@@ -33,6 +33,9 @@ def test_read_only_dict() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
data.setdefault("yo", "yo")
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
data |= {"yo": "yo"}
|
||||
|
||||
assert isinstance(data, dict)
|
||||
assert dict(data) == {"hello": "world"}
|
||||
assert json.dumps(data) == json.dumps({"hello": "world"})
|
||||
|
||||
Reference in New Issue
Block a user