From 608c7d98415aaaf956637ac95649fbfb5610fd39 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 7 Apr 2015 15:49:38 +0000 Subject: [PATCH] Don't rely on exceptions for testing whether a Python attribute names a valid (inverse) IFC attribute --- src/ifcopenshell-python/ifcopenshell/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/__init__.py b/src/ifcopenshell-python/ifcopenshell/__init__.py index 301f02852f..bc4aa43749 100644 --- a/src/ifcopenshell-python/ifcopenshell/__init__.py +++ b/src/ifcopenshell-python/ifcopenshell/__init__.py @@ -43,10 +43,11 @@ class entity_instance(object): def __init__(self, e): super(entity_instance, self).__setattr__('wrapped_data', e) def __getattr__(self, name): - try: return entity_instance.wrap_value(self.wrapped_data.get_argument(self.wrapped_data.get_argument_index(name))) - except: - try: return entity_instance.wrap_value(self.wrapped_data.get_inverse(name)) - except: raise AttributeError("entity instance of type '%s' has no attribute '%s'"%(self.wrapped_data.is_a(), name)) + if name in self.wrapped_data.get_attribute_names(): + return entity_instance.wrap_value(self.wrapped_data.get_argument(self.wrapped_data.get_argument_index(name))) + elif name in self.wrapped_data.get_inverse_attribute_names(): + return entity_instance.wrap_value(self.wrapped_data.get_inverse(name)) + else: raise AttributeError("entity instance of type '%s' has no attribute '%s'"%(self.wrapped_data.is_a(), name)) @staticmethod def map_value(v): if isinstance(v, entity_instance): return v.wrapped_data