From 715019d833339394486b1a374a608ca94a2ef2bb Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Tue, 16 Jan 2024 21:59:15 +0100 Subject: [PATCH] Avoid infinite recursion in set_common_prefix() --- ontopy/ontology.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index b4b416d5a..59076ad4f 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -551,6 +551,7 @@ def set_common_prefix( self, iri_base: str = "http://emmo.info/emmo", prefix: str = "emmo", + visited: "Optional[Set]" = None, ) -> None: """Set a common prefix for all imported ontologies with the same first part of the base_iri. @@ -559,11 +560,18 @@ def set_common_prefix( iri_base: The start of the base_iri to look for. Defaults to the emmo base_iri http://emmo.info/emmo prefix: the desired prefix. Defaults to emmo. + visited: Ontologies to skip. Only intended for internal use. """ + if visited is None: + visited = set() if self.base_iri.startswith(iri_base): self.prefix = prefix for onto in self.imported_ontologies: - onto.set_common_prefix(iri_base=iri_base, prefix=prefix) + if not onto in visited: + visited.add(onto) + onto.set_common_prefix( + iri_base=iri_base, prefix=prefix, visited=visited + ) def load( # pylint: disable=too-many-arguments,arguments-renamed self,