aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/traitlets/py3/traitlets/utils/bunch.py
blob: dc40b5df7d5125068c5d3b92d1ad0c2dd4c12f77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Yet another implementation of bunch 
 
attribute-access of items on a dict. 
""" 
 
# Copyright (c) Jupyter Development Team. 
# Distributed under the terms of the Modified BSD License. 
 
class Bunch(dict): 
    """A dict with attribute-access""" 
    def __getattr__(self, key): 
        try: 
            return self.__getitem__(key) 
        except KeyError: 
            raise AttributeError(key) 
     
    def __setattr__(self, key, value): 
        self.__setitem__(key, value) 
     
    def __dir__(self): 
        # py2-compat: can't use super because dict doesn't have __dir__ 
        names = dir({}) 
        names.extend(self.keys()) 
        return names