From e2256f14999b472ec197e51b9f0c2a8385467eeb Mon Sep 17 00:00:00 2001 From: Isaac To Date: Sun, 29 Sep 2024 16:04:51 -0700 Subject: [PATCH] Bundle `slots` into a list if `use_attributes` is True In this way, the slot definition in `slots` can be added to the class as an attribute, better than raising an exception --- linkml_runtime/utils/schema_builder.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/linkml_runtime/utils/schema_builder.py b/linkml_runtime/utils/schema_builder.py index 79d1e0b8..edbd4e28 100644 --- a/linkml_runtime/utils/schema_builder.py +++ b/linkml_runtime/utils/schema_builder.py @@ -66,7 +66,6 @@ def add_class( :param cls: name, dict object, or ClassDefinition object to add :param slots: slot of slot names or slot objects. - Note: If `use_attributes=True`, then this must be a list of SlotDefinitions :param slot_usage: slots keyed by slot name :param replace_if_present: if True, replace existing class if present :param kwargs: additional ClassDefinition properties @@ -82,9 +81,7 @@ def add_class( self.schema.classes[cls.name] = cls if use_attributes: if not isinstance(slots, list): - raise ValueError( - "If `use_attributes=True`, then `slots` must be a list." - ) + slots = [slots] for s in slots: if isinstance(s, SlotDefinition): cls.attributes[s.name] = s