mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
Validate: better handling of boxed enum
This commit is contained in:
@@ -76,14 +76,21 @@ def assert_valid(attr, val, schema):
|
|||||||
while isinstance(attr_type, type_wrappers):
|
while isinstance(attr_type, type_wrappers):
|
||||||
attr_type = attr_type.declared_type()
|
attr_type = attr_type.declared_type()
|
||||||
|
|
||||||
|
invalid = False
|
||||||
|
|
||||||
if isinstance(attr_type, simple_type):
|
if isinstance(attr_type, simple_type):
|
||||||
invalid = type(val) != simple_type_python_mapping[attr_type.declared_type()]
|
invalid = type(val) != simple_type_python_mapping[attr_type.declared_type()]
|
||||||
elif isinstance(attr_type, (entity_type, type_declaration)):
|
elif isinstance(attr_type, (entity_type, type_declaration)):
|
||||||
invalid = not isinstance(val, ifcopenshell.entity_instance) or not val.is_a(attr_type.name())
|
invalid = not isinstance(val, ifcopenshell.entity_instance) or not val.is_a(attr_type.name())
|
||||||
elif isinstance(attr_type, select_type):
|
elif isinstance(attr_type, select_type):
|
||||||
|
val_to_use = val
|
||||||
if isinstance(schema.declaration_by_name(val.is_a()), enumeration_type):
|
if isinstance(schema.declaration_by_name(val.is_a()), enumeration_type):
|
||||||
val = val.wrappedValue
|
if isinstance(val, ifcopenshell.entity_instance):
|
||||||
invalid = not any(try_valid(x, val, schema) for x in attr_type.select_list())
|
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):
|
elif isinstance(attr_type, enumeration_type):
|
||||||
invalid = val not in attr_type.enumeration_items()
|
invalid = val not in attr_type.enumeration_items()
|
||||||
elif isinstance(attr_type, aggregation_type):
|
elif isinstance(attr_type, aggregation_type):
|
||||||
|
|||||||
Reference in New Issue
Block a user