Skip to content

Commit

Permalink
Check value is a type in comparison methods
Browse files Browse the repository at this point in the history
Check that the compared value is a type in the abstract schema's
comparison methods, otherwise we'll get an exception from issubclass(),
when it's not.
  • Loading branch information
spbnick committed May 21, 2024
1 parent 411f70c commit 1950314
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions kcidb_io/schema/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,28 @@ def __init__(cls, name, bases, _dict, **kwargs):
assert "" in cls.graph

def __le__(cls, other):
if not issubclass(cls, other) and not issubclass(other, cls):
return NotImplemented
return issubclass(other, cls)
if isinstance(other, type) and \
(issubclass(cls, other) or issubclass(other, cls)):
return issubclass(other, cls)
return NotImplemented

def __ge__(cls, other):
if not issubclass(cls, other) and not issubclass(other, cls):
return NotImplemented
return issubclass(cls, other)
if isinstance(other, type) and \
(issubclass(cls, other) or issubclass(other, cls)):
return issubclass(cls, other)
return NotImplemented

def __lt__(cls, other):
if not issubclass(cls, other) and not issubclass(other, cls):
return NotImplemented
return issubclass(other, cls) and cls is not other
if isinstance(other, type) and \
(issubclass(cls, other) or issubclass(other, cls)):
return issubclass(other, cls) and cls is not other
return NotImplemented

def __gt__(cls, other):
if not issubclass(cls, other) and not issubclass(other, cls):
return NotImplemented
return issubclass(cls, other) and cls is not other
if isinstance(other, type) and \
(issubclass(cls, other) or issubclass(other, cls)):
return issubclass(cls, other) and cls is not other
return NotImplemented

@property
def previous(cls):
Expand Down

0 comments on commit 1950314

Please sign in to comment.