MCPcopy Create free account
hub / github.com/apple/ml-pointersect / WarnDict

Class WarnDict

cdslib/core/utils/argparse_utils.py:167–192  ·  view source on GitHub ↗

A dictionary that warns when using get and allows access its key/values like they are its attributes.

Source from the content-addressed store, hash-verified

165
166
167class 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
195def recursive_dict_update(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected