Skip to content

Commit

Permalink
mostly working with vks
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Nov 30, 2020
1 parent 245462a commit e1656f3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions gpkit/keydict.py
Expand Up @@ -44,14 +44,13 @@ class KeyMap:
attribute, that key can be set and accessed normally.
"""
collapse_arrays = False
keymap = []
keymap = defaultdict(set)
log_gets = False
varkeys = None
vks = None

def __init__(self, *args, **kwargs):
"Passes through to super().__init__ via the `update()` method"
self.keymap = defaultdict(set)
self._unmapped_keys = set()
self.owned = set()
self.update(*args, **kwargs) # pylint: disable=no-member
Expand Down Expand Up @@ -106,7 +105,7 @@ def __contains__(self, key): # pylint:disable=too-many-return-statements
" for value %s" %
(key, idx, super().__getitem__(key))) # pylint: disable=no-member
return True
return key in self.keymap
return any(super().__contains__(k) for k in self.keymap[key])

def update_keymap(self):
"Updates the keymap with the keys in _unmapped_keys"
Expand Down Expand Up @@ -172,7 +171,10 @@ def __call__(self, key): # if uniting is ever a speed hit, cache it
def __getitem__(self, key):
"Overloads __getitem__ and [] access to work with all keys"
key, idx = self.parse_and_index(key)
keys = self.keymap[key]
if super().__contains__(key):
keys = [key]
else:
keys = self.keymap[key]
if not keys:
del self.keymap[key] # remove blank entry added by defaultdict
raise KeyError(key)
Expand Down

0 comments on commit e1656f3

Please sign in to comment.