[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:
Fabien Castan 2024-06-15 17:10:46 +02:00
parent 09525a364e
commit c986b4a134
4 changed files with 42 additions and 25 deletions

View file

@ -43,7 +43,9 @@ class QObjectListModel(QtCore.QAbstractListModel):
return self.size() > 0
def __getitem__(self, index):
""" Enables the [] operator """
""" Enables the [] operator.
Only accepts index (integer).
"""
return self._objects[index]
def data(self, index, role):
@ -96,9 +98,17 @@ class QObjectListModel(QtCore.QAbstractListModel):
@QtCore.Slot(str, result=QtCore.QObject)
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._objectByKey.get(key)
@QtCore.Slot(str, result=QtCore.QObject)
def getr(self, key):
"""
Get or raise an error if the key does not exists.
:param key:
:return: the value
"""
return self._objectByKey[key]