Closed jwreep closed 3 months ago
This is once again a consequence of my poor design choices! The exception occurs because the attribute does indeed exist but there's no data to be accessed, hence the KeyError
.
I think a good solution here would be to add a private method to the Ion class that allows you to check whether the needed data exists for that ion. This could come in handy in a few other places as well.
Here's an example of how you might implement this using the needs_dataset
decorator:
def _has_dataset(self, dset_name):
try:
needs_dataset(dset_name)(lambda _: None)(self)
except MissingDatasetException:
return False
else:
return True
I wrote this on mobile without testing anything but I think that should work.
I should add, the reason for not just using hasattr
for all this is we want the attributes to exist even if the data doesn't since different ions have different data attached to them and the types of data attached to a given ion may change from one database version to the next.
To test whether an ion has dielectronic data, I would think that we could write, e.g.:
which should in principle return
False
since there is no dielectronic data. It does correctly returnTrue
when the data does exist. However, when it doesn't exist, it returns aKeyError
because fiasco is still attempting to access the non-existent data:Presumably, it shouldn't try to access the data here! Not sure what the fix is off the top of my head, but I wouldn't think this is the desired behavior.