From 6302d3bd9699e8ce64be0aa23719f74aa71d31a8 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Fri, 22 Nov 2024 17:02:50 +0100 Subject: [PATCH] allow both graph and types in ModelBase --- src/rdf_utils/models/common.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/rdf_utils/models/common.py b/src/rdf_utils/models/common.py index e437bb1..a48a764 100644 --- a/src/rdf_utils/models/common.py +++ b/src/rdf_utils/models/common.py @@ -29,17 +29,13 @@ def __init__( self, node_id: URIRef, graph: Optional[Graph] = None, types: Optional[set[URIRef]] = None ) -> None: self.id = node_id - if graph is not None: - self.types = get_node_types(graph=graph, node_id=node_id) - assert ( - types is None - ), f"ModelBase.__init__: node '{node_id}': both 'graph' and 'types' args are not None" - elif types is not None: + if types is not None: self.types = types else: - raise RuntimeError( - f"ModelBase.__init__: node '{node_id}': neither 'graph' or 'types' specified" - ) + assert ( + graph is not None + ), f"ModelBase.__init__: node '{node_id}': neither 'graph' or 'types' specified" + self.types = get_node_types(graph=graph, node_id=node_id) assert len(self.types) > 0, f"node '{self.id}' has no type" self._attributes = {}