Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the getattr patch #699

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ontopy/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# Extending ThingClass (classes)
# ==============================

# Save a copy of the unpatched ThingClass.__getattr__() method.
save_getattr = ThingClass.__getattr__


Expand Down Expand Up @@ -133,7 +134,13 @@
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)

Check warning on line 143 in ontopy/patch.py

View check run for this annotation

Codecov / codecov/patch

ontopy/patch.py#L142-L143

Added lines #L142 - L143 were not covered by tests
raise err


Expand Down