Skip to content

Mixins for standard collections that implement collections.abc interfaces #1543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 23, 2021
Prev Previous commit
Next Next commit
fixed mixin calls to TryGetValue
  • Loading branch information
lostmsu committed Sep 22, 2021
commit 38ac73b9e883b3f00fb7b51d20e8931566f00071
8 changes: 4 additions & 4 deletions src/runtime/Mixins/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class MutableSequenceMixin(SequenceMixin, col.MutableSequence):
class MappingMixin(CollectionMixin, col.Mapping):
def __contains__(self, item): return self.ContainsKey(item)
def keys(self): return self.Keys
def items(self): return [(k,self[k]) for k in self.Keys]
def items(self): return [(k,self.get(k)) for k in self.Keys]
def values(self): return self.Values
def __iter__(self): return self.Keys.__iter__()
def get(self, key, default=None):
existed, item = self.TryGetValue(key)
existed, item = self.TryGetValue(key, None)
return item if existed else default

class MutableMappingMixin(MappingMixin, col.MutableMapping):
Expand All @@ -53,7 +53,7 @@ def clear(self):
self.Clear()

def pop(self, key, default=_UNSET_):
existed, item = self.TryGetValue(key)
existed, item = self.TryGetValue(key, None)
if existed:
self.Remove(key)
return item
Expand All @@ -63,7 +63,7 @@ def pop(self, key, default=_UNSET_):
return default

def setdefault(self, key, value=None):
existed, item = self.TryGetValue(key)
existed, item = self.TryGetValue(key, None)
if existed:
return item
else:
Expand Down