A dictionary that warns when using get and allows access its key/values like they are its attributes.
| 165 | |
| 166 | |
| 167 | class WarnDict(dict): |
| 168 | """ |
| 169 | A dictionary that warns when using get and allows access its key/values |
| 170 | like they are its attributes. |
| 171 | """ |
| 172 | |
| 173 | def __init__(self, *args, **kwargs): |
| 174 | super().__init__(*args, **kwargs) |
| 175 | |
| 176 | def get(self, key, default=None): |
| 177 | if key not in self: |
| 178 | warnings.warn(f"access {key} not in dict, use {default}") |
| 179 | |
| 180 | return super().get(key, default) |
| 181 | |
| 182 | def __getattr__(self, name: str) -> T.Any: |
| 183 | try: |
| 184 | return self[name] |
| 185 | except KeyError: |
| 186 | raise AttributeError(name) |
| 187 | |
| 188 | def __setattr__(self, name: str, value: T.Any) -> None: |
| 189 | self[name] = value |
| 190 | |
| 191 | def __delattr__(self, name: str) -> None: |
| 192 | del self[name] |
| 193 | |
| 194 | |
| 195 | def recursive_dict_update( |
nothing calls this directly
no outgoing calls
no test coverage detected