| 54 | |
| 55 | |
| 56 | class FrozenDict(OrderedDict): |
| 57 | def __init__(self, *args, **kwargs): |
| 58 | super().__init__(*args, **kwargs) |
| 59 | |
| 60 | for key, value in self.items(): |
| 61 | setattr(self, key, value) |
| 62 | |
| 63 | self.__frozen = True |
| 64 | |
| 65 | def __delitem__(self, *args, **kwargs): |
| 66 | raise Exception(f"You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.") |
| 67 | |
| 68 | def setdefault(self, *args, **kwargs): |
| 69 | raise Exception(f"You cannot use ``setdefault`` on a {self.__class__.__name__} instance.") |
| 70 | |
| 71 | def pop(self, *args, **kwargs): |
| 72 | raise Exception(f"You cannot use ``pop`` on a {self.__class__.__name__} instance.") |
| 73 | |
| 74 | def update(self, *args, **kwargs): |
| 75 | raise Exception(f"You cannot use ``update`` on a {self.__class__.__name__} instance.") |
| 76 | |
| 77 | def __setattr__(self, name, value): |
| 78 | if hasattr(self, "__frozen") and self.__frozen: |
| 79 | raise Exception(f"You cannot use ``__setattr__`` on a {self.__class__.__name__} instance.") |
| 80 | super().__setattr__(name, value) |
| 81 | |
| 82 | def __setitem__(self, name, value): |
| 83 | if hasattr(self, "__frozen") and self.__frozen: |
| 84 | raise Exception(f"You cannot use ``__setattr__`` on a {self.__class__.__name__} instance.") |
| 85 | super().__setitem__(name, value) |
| 86 | |
| 87 | |
| 88 | class ConfigMixin: |
no outgoing calls
no test coverage detected
searching dependent graphs…