From 4cd8428d1de496bf2e23570055bcde81bad1e03e Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Wed, 30 Oct 2024 08:46:50 +0100 Subject: [PATCH] Update unit.py --- .../ifcopenshell/util/unit.py | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index 041021d5b9..0b341b0f37 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -725,27 +725,25 @@ def format_length( def is_attr_type( - content_type: ifcopenshell_wrapper.parameter_type, ifc_unit_type_name: str, include_select_types: bool = True + content_type: ifcopenshell_wrapper.parameter_type, + ifc_unit_type_name: str, + include_select_types: bool = True, ) -> Union[ifcopenshell_wrapper.type_declaration, None]: cur_decl = content_type + if hasattr(cur_decl, "name") and cur_decl.name() == ifc_unit_type_name: + return cur_decl + if include_select_types: if hasattr(cur_decl, "select_list"): for select_item in cur_decl.select_list(): if is_attr_type(select_item, ifc_unit_type_name): return select_item - while hasattr(cur_decl, "declared_type") is True: - cur_decl = cur_decl.declared_type() - if include_select_types: - if hasattr(cur_decl, "select_list"): - for select_item in cur_decl.select_list(): - if is_attr_type(select_item, ifc_unit_type_name): - return select_item - if hasattr(cur_decl, "name") is False: - continue - if cur_decl.name() == ifc_unit_type_name: - return cur_decl + if hasattr(cur_decl, "declared_type"): + return is_attr_type( + cur_decl.declared_type(), ifc_unit_type_name, include_select_types + ) if isinstance(cur_decl, ifcopenshell_wrapper.aggregation_type): # support aggregate of aggregates, as in IfcCartesianPointList3D.CoordList @@ -756,14 +754,7 @@ def is_attr_type( return get_declared_type_from_aggregate(cur_decl) cur_decl = get_declared_type_from_aggregate(cur_decl) - if hasattr(cur_decl, "name") and cur_decl.name() == ifc_unit_type_name: - return cur_decl - while hasattr(cur_decl, "declared_type") is True: - cur_decl = cur_decl.declared_type() - if hasattr(cur_decl, "name") is False: - continue - if cur_decl.name() == ifc_unit_type_name: - return cur_decl + return is_attr_type(cur_decl, ifc_unit_type_name, include_select_types) return None