From 7a2d9934ec7ce48f4698f1d6906e8b3f35c1e9f8 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Wed, 17 Jan 2024 08:26:55 +0100 Subject: [PATCH] Avoid infinite recursion in set_common_prefix() (#701) # Description Avoid infinite recursion in set_common_prefix() ## Type of change - [x] Bug fix. - [ ] New feature. - [ ] Documentation update. - [ ] Test update. ## Checklist This checklist can be used as a help for the reviewer. - [ ] Is the code easy to read and understand? - [ ] Are comments for humans to read, not computers to disregard? - [ ] Does a new feature has an accompanying new test (in the CI or unit testing schemes)? - [ ] Has the documentation been updated as necessary? - [ ] Does this close the issue? - [ ] Is the change limited to the issue? - [ ] Are errors handled for all outcomes? - [ ] Does the new feature provide new restrictions on dependencies, and if so is this documented? ## Comments --- 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,