Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/invoke/vendor/lexicon/__init__.py: 50%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

12 statements  

1from ._version import __version_info__, __version__ # noqa 

2from .attribute_dict import AttributeDict 

3from .alias_dict import AliasDict 

4 

5 

6class Lexicon(AttributeDict, AliasDict): 

7 def __init__(self, *args, **kwargs): 

8 # Need to avoid combining AliasDict's initial attribute write on 

9 # self.aliases, with AttributeDict's __setattr__. Doing so results in 

10 # an infinite loop. Instead, just skip straight to dict() for both 

11 # explicitly (i.e. we override AliasDict.__init__ instead of extending 

12 # it.) 

13 # NOTE: could tickle AttributeDict.__init__ instead, in case it ever 

14 # grows one. 

15 dict.__init__(self, *args, **kwargs) 

16 dict.__setattr__(self, "aliases", {}) 

17 

18 def __getattr__(self, key): 

19 # Intercept deepcopy/etc driven access to self.aliases when not 

20 # actually set. (Only a problem for us, due to abovementioned combo of 

21 # Alias and Attribute Dicts, so not solvable in a parent alone.) 

22 if key == "aliases" and key not in self.__dict__: 

23 self.__dict__[key] = {} 

24 return super(Lexicon, self).__getattr__(key)