Skip to content

Commit

Permalink
Simplify __eq__ logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zero323 committed Nov 1, 2015
1 parent d2e492c commit a3d54bf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tryingsnake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,8 @@ def __eq__(self, other):
>>> Success(1) == 1
False
"""
if isinstance(other, Success):
return self._v == other._v
return False
return (isinstance(other, Success) and
self._v == other._v)

def get(self):
return self._v
Expand Down Expand Up @@ -279,13 +278,12 @@ def __eq__(self, other):
>>> Failure(Exception("e")) == Exception("e")
False
"""
if isinstance(other, Failure):
this_type = type(self._v)
other_type = type(other._v)

return (this_type == other_type and # match exact type
self._v.args == other._v.args)
return False
return (
isinstance(other, Failure) and
# Want to check an exact type so isinstance or issubclass
# are not good here
type(self._v) is type(other._v) and
self._v.args == other._v.args)

def get(self):
raise self._v
Expand Down

0 comments on commit a3d54bf

Please sign in to comment.