Skip to content

Commit

Permalink
Avoid infinite recursion in set_common_prefix() (#701)
Browse files Browse the repository at this point in the history
# Description
Avoid infinite recursion in set_common_prefix()

## Type of change
<!-- Put an `x` in the box that applies. -->
- [x] Bug fix.
- [ ] New feature.
- [ ] Documentation update.
- [ ] Test update.

## Checklist
<!-- Put an `x` in the boxes that apply. You can also fill these out
after creating the PR. -->

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
<!-- Additional comments here, including clarifications on checklist if
applicable. -->
  • Loading branch information
jesper-friis authored Jan 17, 2024
1 parent 55e1885 commit 7a2d993
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down

0 comments on commit 7a2d993

Please sign in to comment.