File: __init__.py

package info (click to toggle)
python-invoke 0.11.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,136 kB
  • ctags: 1,702
  • sloc: python: 5,614; makefile: 37; sh: 36
file content (23 lines) | stat: -rw-r--r-- 1,073 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from .attribute_dict import AttributeDict
from .alias_dict import AliasDict


class Lexicon(AttributeDict, AliasDict):
    def __init__(self, *args, **kwargs):
        # Need to avoid combining AliasDict's initial attribute write on
        # self.aliases, with AttributeDict's __setattr__. Doing so results in
        # an infinite loop. Instead, just skip straight to dict() for both
        # explicitly (i.e. we override AliasDict.__init__ instead of extending
        # it.)
        # NOTE: could tickle AttributeDict.__init__ instead, in case it ever
        # grows one.
        dict.__init__(self, *args, **kwargs)
        dict.__setattr__(self, 'aliases', {})

    def __getattr__(self, key):
        # Intercept deepcopy/etc driven access to self.aliases when not
        # actually set. (Only a problem for us, due to abovementioned combo of
        # Alias and Attribute Dicts, so not solvable in a parent alone.)
        if key == 'aliases' and key not in self.__dict__:
            self.__dict__[key] = {}
        return super(Lexicon, self).__getattr__(key)