-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Given a Group group, the following always evaluates to True:
NXdata in groupAnd the same applies to all NX classes.
The reason is that we don't define Group.__contains__. So Python uses the fallback for mappings:
def __contains__(self, key):
try:
self[key]
except KeyError:
return False
else:
return TrueBut group[NXdata] returns an empty dict if there is no NXdata in the group. So __contains__ is always True.
This is surprising behaviour. I think we have two options to fix it without breaking anything:
- Actually check whether there are any children with the given class. This fixes the use case I have. But it creates an inconsistency between
__contains__and__getitem__. - Raise a
TypeErrorwhen__contains__is called with anything but a `str. This also creates an inconsistency. But I think this one is less severe.
Alternatively, we could change the behaviour of __getitem__ to raise when there is no child with the given class.
Or we leave it as. This keeps the mapping API consistent. But this can easily lead to errors downstream.
Metadata
Metadata
Assignees
Labels
No labels