A dict with attribute-access
| 11 | |
| 12 | |
| 13 | class Bunch(dict): # type:ignore[type-arg] |
| 14 | """A dict with attribute-access""" |
| 15 | |
| 16 | def __getattr__(self, key: str) -> Any: |
| 17 | try: |
| 18 | return self.__getitem__(key) |
| 19 | except KeyError as e: |
| 20 | raise AttributeError(key) from e |
| 21 | |
| 22 | def __setattr__(self, key: str, value: Any) -> None: |
| 23 | self.__setitem__(key, value) |
| 24 | |
| 25 | def __dir__(self) -> list[str]: |
| 26 | names: list[str] = [] |
| 27 | names.extend(super().__dir__()) |
| 28 | names.extend(self.keys()) |
| 29 | return names |
no outgoing calls
searching dependent graphs…