mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-31 23:38:48 +02:00
[common] DictModel get does not raise errors as in Python
getr raises an error if the key does not exist
This commit is contained in:
parent
09525a364e
commit
c986b4a134
4 changed files with 42 additions and 25 deletions
|
@ -9,6 +9,9 @@ class CoreDictModel:
|
|||
def __len__(self):
|
||||
return len(self._objects)
|
||||
|
||||
def __bool__(self):
|
||||
return bool(self._objects)
|
||||
|
||||
def __iter__(self):
|
||||
""" Enables iteration over the list of objects. """
|
||||
return iter(self._objects.values())
|
||||
|
@ -26,12 +29,18 @@ class CoreDictModel:
|
|||
def objects(self):
|
||||
return self._objects
|
||||
|
||||
# TODO: operator[]
|
||||
def get(self, key):
|
||||
"""
|
||||
Raises a KeyError if key is not in the map.
|
||||
:param key:
|
||||
:return:
|
||||
:return: the value or None if not found
|
||||
"""
|
||||
return self._objects.get(key)
|
||||
|
||||
def getr(self, key):
|
||||
"""
|
||||
Get or raise an error if the key does not exists.
|
||||
:param key:
|
||||
:return: the value
|
||||
"""
|
||||
return self._objects[key]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue