Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/traitlets/utils/bunch.py: 43%
14 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-20 06:09 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-20 06:09 +0000
1"""Yet another implementation of bunch
3attribute-access of items on a dict.
4"""
6# Copyright (c) Jupyter Development Team.
7# Distributed under the terms of the Modified BSD License.
8from __future__ import annotations
10from typing import Any
13class Bunch(dict): # type:ignore[type-arg]
14 """A dict with attribute-access"""
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
22 def __setattr__(self, key: str, value: Any) -> None:
23 self.__setitem__(key, value)
25 def __dir__(self) -> list[str]:
26 # py2-compat: can't use super because dict doesn't have __dir__
27 names = dir({})
28 names.extend(self.keys())
29 return names