From b715d2e3c9f5c1e56e68cd914b19fb2fd57aab57 Mon Sep 17 00:00:00 2001 From: Benjamin Robin Date: Tue, 9 Sep 2025 16:24:29 +0200 Subject: [PATCH] template/python.j2: Allow to remove object from object set For simplicity, rebuild the index from scratch instead of trying to remove the object from the index. --- src/shacl2code/lang/templates/python.j2 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/shacl2code/lang/templates/python.j2 b/src/shacl2code/lang/templates/python.j2 index 92d54e33..01e1d713 100644 --- a/src/shacl2code/lang/templates/python.j2 +++ b/src/shacl2code/lang/templates/python.j2 @@ -1188,6 +1188,19 @@ class SHACLObjectSet(object): self.add_index(obj) return obj + def remove(self, obj: SHACLObject) -> None: + """ + Remove object from object set + + Remove a SHACLObject from the object set and rebuild index. + """ + if not isinstance(obj, SHACLObject): + raise TypeError("Object is not of type SHACLObject") + + if obj in self.objects: + self.objects.remove(obj) + self.create_index() + def update(self, *others) -> None: """ Update object set adding all objects in each other iterable