From 4fb65199b80a81048d36b42559bfbd3c6e2007a8 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 14 Feb 2021 17:32:08 +0100 Subject: [PATCH] Validate: better handling of boxed enum --- src/ifcopenshell-python/ifcopenshell/validate.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/validate.py b/src/ifcopenshell-python/ifcopenshell/validate.py index 952ede596d..bc5e2054f9 100644 --- a/src/ifcopenshell-python/ifcopenshell/validate.py +++ b/src/ifcopenshell-python/ifcopenshell/validate.py @@ -75,15 +75,22 @@ def assert_valid(attr, val, schema): while isinstance(attr_type, type_wrappers): attr_type = attr_type.declared_type() + + invalid = False if isinstance(attr_type, simple_type): invalid = type(val) != simple_type_python_mapping[attr_type.declared_type()] elif isinstance(attr_type, (entity_type, type_declaration)): invalid = not isinstance(val, ifcopenshell.entity_instance) or not val.is_a(attr_type.name()) elif isinstance(attr_type, select_type): + val_to_use = val if isinstance(schema.declaration_by_name(val.is_a()), enumeration_type): - val = val.wrappedValue - invalid = not any(try_valid(x, val, schema) for x in attr_type.select_list()) + if isinstance(val, ifcopenshell.entity_instance): + val_to_use = val.wrappedValue + else: + invalid = True + if not invalid: + invalid = not any(try_valid(x, val_to_use, schema) for x in attr_type.select_list()) elif isinstance(attr_type, enumeration_type): invalid = val not in attr_type.enumeration_items() elif isinstance(attr_type, aggregation_type):