From dbd1ca86fd78425ea73021b8b42a0ad8b47f8698 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Tue, 16 Jan 2024 19:16:05 +0100 Subject: [PATCH] Updated the getattr patch Ensure that we can access annotations added by imported ontologies. --- ontopy/patch.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ontopy/patch.py b/ontopy/patch.py index 61c68e50c..2b744b5aa 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -29,6 +29,7 @@ def render_func(entity): # Extending ThingClass (classes) # ============================== +# Save a copy of the unpatched ThingClass.__getattr__() method. save_getattr = ThingClass.__getattr__ @@ -133,7 +134,13 @@ def _getattr(self, name): entity = self.namespace.ontology.get_by_label(name) # add annotation property to world._props for faster access later self.namespace.world._props[name] = entity - return save_getattr(self, entity.name) + + # Try first unpatched getattr method to avoid risking + # infinite recursion. + try: + return save_getattr(self, entity.name) + except AttributeError: + return getattr(self, entity.name) raise err