1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-26 05:57:01 +00:00
Files
core/homeassistant/util/read_only_dict.py
2024-05-20 10:44:52 +02:00

21 lines
513 B
Python

"""Read only dictionary."""
from typing import Any
def _readonly(*args: Any, **kwargs: Any) -> Any:
"""Raise an exception when a read only dict is modified."""
raise RuntimeError("Cannot modify ReadOnlyDict")
class ReadOnlyDict[_KT, _VT](dict[_KT, _VT]):
"""Read only version of dict that is compatible with dict types."""
__setitem__ = _readonly
__delitem__ = _readonly
pop = _readonly
popitem = _readonly
clear = _readonly
update = _readonly
setdefault = _readonly