suggestion by Paul Romano. removed need for _get_tally_index_ funciton by using python's fancy self[key] and self[key]._index capabilities

This commit is contained in:
lewisgross1296 2022-08-15 14:49:36 -05:00
parent 7fdd96a573
commit 15a863e645

View file

@ -390,7 +390,7 @@ class Tally(_FortranObjectWithID):
class _TallyMapping(Mapping):
def __getitem__(self, key):
return Tally(index=self._get_tally_index(key))
return Tally(index=self[key])
def __iter__(self):
for i in range(len(self)):
@ -404,16 +404,6 @@ class _TallyMapping(Mapping):
def __delitem__(self, key):
"""Delete a tally from tally vector and remove the ID,index pair from tally"""
_dll.openmc_remove_tally(self._get_tally_index(key))
def _get_tally_index(self, key):
"""Given the ID, return the index"""
index = c_int32()
try:
_dll.openmc_get_tally_index(key, index)
except (AllocationError, InvalidIDError) as e:
# __contains__ expects a KeyError to work correctly
raise KeyError(str(e))
return index.value
_dll.openmc_remove_tally(self[key]._index)
tallies = _TallyMapping()