Skip to content

Commit

Permalink
Return NotImplemented from comparison methods
Browse files Browse the repository at this point in the history
Return NotImplemented from comparison methods, as is standard approach,
instead of raising NotImplementedError, in the abstract schema.
  • Loading branch information
spbnick committed May 21, 2024
1 parent ce24dda commit 411f70c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions kcidb_io/schema/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ def __init__(cls, name, bases, _dict, **kwargs):

def __le__(cls, other):
if not issubclass(cls, other) and not issubclass(other, cls):
raise NotImplementedError
return NotImplemented
return issubclass(other, cls)

def __ge__(cls, other):
if not issubclass(cls, other) and not issubclass(other, cls):
raise NotImplementedError
return NotImplemented
return issubclass(cls, other)

def __lt__(cls, other):
if not issubclass(cls, other) and not issubclass(other, cls):
raise NotImplementedError
return NotImplemented
return issubclass(other, cls) and cls is not other

def __gt__(cls, other):
if not issubclass(cls, other) and not issubclass(other, cls):
raise NotImplementedError
return NotImplemented
return issubclass(cls, other) and cls is not other

@property
Expand Down
8 changes: 4 additions & 4 deletions kcidb_io/schema/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ def _inherit(data):
self.assertFalse(V1 > V2A)
self.assertFalse(V1 > V2B)

with self.assertRaises(NotImplementedError):
with self.assertRaises(TypeError):
self.assertTrue(V2A < V2B)
with self.assertRaises(NotImplementedError):
with self.assertRaises(TypeError):
self.assertTrue(V2A > V2B)
with self.assertRaises(NotImplementedError):
with self.assertRaises(TypeError):
self.assertTrue(V2A <= V2B)
with self.assertRaises(NotImplementedError):
with self.assertRaises(TypeError):
self.assertTrue(V2A >= V2B)

0 comments on commit 411f70c

Please sign in to comment.