Skip to content

Commit

Permalink
Added rich comparison functions for bitfield.
Browse files Browse the repository at this point in the history
  • Loading branch information
Candoran2 committed Sep 19, 2021
1 parent e7bdd73 commit 6ccb132
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions source/bitfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ def __hash__(self):
def __int__(self):
return self._value

def __eq__(self, other):
if isinstance(other, BasicBitfield):
return self._value == other._value
elif isinstance(other, int):
return self._value == other
return False

def __init__(self, value=None):
super().__init__()
if value is not None:
Expand All @@ -61,6 +54,24 @@ def __str__(self):
info += f"\n\t{field} = {str(val)}"
return info

# rich comparison methods
def __lt__(self, other):
return self._value < other

def __le__(self, other):
return self._value <= other

def __eq__(self, other):
return self._value == other

def __ne__(self, other):
return self._value != other

def __gt__(self, other):
return self._value > other

def __ge__(self, other):
return self._value >= other

# basic arithmetic functions
def __add__(self, other):
Expand Down

0 comments on commit 6ccb132

Please sign in to comment.