From 5e3a9e08b71ad7435a31326124afe8b43876138f Mon Sep 17 00:00:00 2001 From: Caglar Demir Date: Fri, 8 Nov 2024 16:44:12 +0100 Subject: [PATCH] Raised RuntimeError if two objects not inherting from same abstract class are compared --- owlapy/iri.py | 4 +++- owlapy/owl_object.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/owlapy/iri.py b/owlapy/iri.py index 66166bb4..af6a3238 100644 --- a/owlapy/iri.py +++ b/owlapy/iri.py @@ -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 @@ -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)) diff --git a/owlapy/owl_object.py b/owlapy/owl_object.py index 02894034..2f89a877 100644 --- a/owlapy/owl_object.py +++ b/owlapy/owl_object.py @@ -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):