Skip to content

Commit

Permalink
Raised RuntimeError if two objects not inherting from same abstract c…
Browse files Browse the repository at this point in the history
…lass are compared
  • Loading branch information
Demirrr committed Nov 8, 2024
1 parent 5038f0d commit 5e3a9e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion owlapy/iri.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, namespace: Union[str, Namespaces], remainder: str=""):
else:
assert namespace[-1] in ("/", ":", "#"), "It should be a valid IRI based on /, :, and #"
import sys
# https://docs.python.org/3.2/library/sys.html?highlight=sys.intern#sys.intern
self._namespace = sys.intern(namespace)
self._remainder = remainder

Expand Down Expand Up @@ -94,7 +95,8 @@ def __repr__(self):
def __eq__(self, other):
if type(other) is type(self):
return self._namespace is other._namespace and self._remainder == other._remainder
return NotImplemented
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")

def __hash__(self):
return hash((self._namespace, self._remainder))
Expand Down
3 changes: 2 additions & 1 deletion owlapy/owl_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class OWLNamedObject(OWLObject, HasIRI, metaclass=ABCMeta):
def __eq__(self, other):
if type(other) is type(self):
return self._iri == other._iri
return NotImplemented
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")

def __lt__(self, other):
if type(other) is type(self):
Expand Down

0 comments on commit 5e3a9e0

Please sign in to comment.