Skip to content

Commit 1f2c6da

Browse files
committed
refactor: logical dunder to simplify logic
1 parent 4690a86 commit 1f2c6da

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

ResultContainer/ResultContainer.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,10 +1637,8 @@ def __float__(self): # To get called by built-in float() method to convert a ty
16371637
def __lt__(self, other): # compare self < other.
16381638
# Assumes Err() < Ok() and Err(a) == Err(b)
16391639
self._empty_error()
1640-
if isinstance(other, ResultErr):
1641-
other = Result(other, False)
1642-
elif not isinstance(other, Result):
1643-
other = Result(other, True)
1640+
if not isinstance(other, Result):
1641+
other = Result(other)
16441642

16451643
if self.is_Ok and other.is_Ok:
16461644
return self._Ok < other._Ok
@@ -1649,10 +1647,8 @@ def __lt__(self, other): # compare self < other.
16491647
def __le__(self, other): # compare self <= other.
16501648
# Assumes Err() < Ok() and Err(a) == Err(b)
16511649
self._empty_error()
1652-
if isinstance(other, ResultErr):
1653-
other = Result(other, False)
1654-
elif not isinstance(other, Result):
1655-
other = Result(other, True)
1650+
if not isinstance(other, Result):
1651+
other = Result(other)
16561652

16571653
if self.is_Ok and other.is_Ok:
16581654
return self._Ok <= other._Ok
@@ -1661,10 +1657,8 @@ def __le__(self, other): # compare self <= other.
16611657
def __gt__(self, other): # compare self > other.
16621658
# Assumes Err() < Ok() and Err(a) == Err(b)
16631659
self._empty_error()
1664-
if isinstance(other, ResultErr):
1665-
other = Result(other, False)
1666-
elif not isinstance(other, Result):
1667-
other = Result(other, True)
1660+
if not isinstance(other, Result):
1661+
other = Result(other)
16681662

16691663
if self.is_Ok and other.is_Ok:
16701664
return self._Ok > other._Ok
@@ -1673,10 +1667,8 @@ def __gt__(self, other): # compare self > other.
16731667
def __ge__(self, other): # compare self >= other.
16741668
# Assumes Err() < Ok() and Err(a) == Err(b)
16751669
self._empty_error()
1676-
if isinstance(other, ResultErr):
1677-
other = Result(other, False)
1678-
elif not isinstance(other, Result):
1679-
other = Result(other, True)
1670+
if not isinstance(other, Result):
1671+
other = Result(other)
16801672

16811673
if self.is_Ok and other.is_Ok:
16821674
return self._Ok >= other._Ok
@@ -1685,10 +1677,8 @@ def __ge__(self, other): # compare self >= other.
16851677
def __eq__(self, other): # compare self == other.
16861678
# Assumes Ok(a) == Ok(b) if a == b, but Err(a) == Err(b) for any a or b.
16871679
self._empty_error()
1688-
if isinstance(other, ResultErr):
1689-
other = Result(other, False)
1690-
elif not isinstance(other, Result):
1691-
other = Result(other, True)
1680+
if not isinstance(other, Result):
1681+
other = Result(other)
16921682

16931683
if self.is_Ok and other.is_Ok:
16941684
return self._Ok == other._Ok
@@ -1697,10 +1687,8 @@ def __eq__(self, other): # compare self == other.
16971687
def __ne__(self, other): # compare self != other.
16981688
# Assumes Ok(a) == Ok(b) if a == b, but Err(a) == Err(b) for any a or b.
16991689
self._empty_error()
1700-
if isinstance(other, ResultErr):
1701-
other = Result(other, False)
1702-
elif not isinstance(other, Result):
1703-
other = Result(other, True)
1690+
if not isinstance(other, Result):
1691+
other = Result(other)
17041692

17051693
if self.is_Ok and other.is_Ok:
17061694
return self._Ok != other._Ok

0 commit comments

Comments
 (0)