Skip to content

Commit

Permalink
Improve CyclicInt type
Browse files Browse the repository at this point in the history
  • Loading branch information
moomoohk committed Dec 2, 2022
1 parent 58407db commit 317e3cd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dpath/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ def __new__(cls, value: int, max_value: int, *args, **kwargs):
return obj

def __eq__(self, other):
if not isinstance(other, int):
return False

return int(self) == (self.max_value + other) % self.max_value

def __repr__(self):
return f"<CyclicInt {int(self)}/{self.max_value}>"
return f"<CyclicInt {int(self)}%{self.max_value}>"

def __str__(self):
return str(int(self))
Expand Down

0 comments on commit 317e3cd

Please sign in to comment.