| 1 |
from ._version import __version_info__, __version__ # noqa |
| 2 |
from .attribute_dict import AttributeDict |
| 3 |
from .alias_dict import AliasDict |
| 4 |
|
| 5 |
|
| 6 |
class 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) |