Skip to content

Commit 608c7d9

Browse files
committed
Don't rely on exceptions for testing whether a Python attribute names a valid (inverse) IFC attribute
1 parent 955190b commit 608c7d9

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/ifcopenshell-python/ifcopenshell/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ class entity_instance(object):
4343
def __init__(self, e):
4444
super(entity_instance, self).__setattr__('wrapped_data', e)
4545
def __getattr__(self, name):
46-
try: return entity_instance.wrap_value(self.wrapped_data.get_argument(self.wrapped_data.get_argument_index(name)))
47-
except:
48-
try: return entity_instance.wrap_value(self.wrapped_data.get_inverse(name))
49-
except: raise AttributeError("entity instance of type '%s' has no attribute '%s'"%(self.wrapped_data.is_a(), name))
46+
if name in self.wrapped_data.get_attribute_names():
47+
return entity_instance.wrap_value(self.wrapped_data.get_argument(self.wrapped_data.get_argument_index(name)))
48+
elif name in self.wrapped_data.get_inverse_attribute_names():
49+
return entity_instance.wrap_value(self.wrapped_data.get_inverse(name))
50+
else: raise AttributeError("entity instance of type '%s' has no attribute '%s'"%(self.wrapped_data.is_a(), name))
5051
@staticmethod
5152
def map_value(v):
5253
if isinstance(v, entity_instance): return v.wrapped_data

0 commit comments

Comments
 (0)