Skip to content

Commit

Permalink
Merge c5c8ad8 into 69f5add
Browse files Browse the repository at this point in the history
  • Loading branch information
vaab committed Apr 8, 2017
2 parents 69f5add + c5c8ad8 commit 8a6d439
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.rst
Expand Up @@ -296,6 +296,8 @@ But on another non-Colour object::

>>> red == None
False
>>> red != None
True

Actually, ``Colour`` instances will, politely enough, leave
the other side of the equality have a chance to decide of the output,
Expand All @@ -313,6 +315,18 @@ the other side of the equality have a chance to decide of the output,
>>> blue == alien_red
False

And inequality (using ``__ne__``) are also polite::

>>> class AnotherColorImplem(OtherColorImplem):
... def __ne__(self, other):
... return self.color != other.web

>>> new_alien_red = AnotherColorImplem("red")
>>> red != new_alien_red
False
>>> blue != new_alien_red
True


Picking arbitrary color for a python object
-------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions colour.py
Expand Up @@ -931,6 +931,12 @@ class Color(object):
>>> Color('red') == Color('blue')
False
>>> Color('red') == Color('red')
True
>>> Color('red') != Color('blue')
True
>>> Color('red') != Color('red')
False
But this can be changed:
Expand Down Expand Up @@ -1091,6 +1097,13 @@ def __eq__(self, other):
return self.equality(self, other)
return NotImplemented

## Note: intended to be a backport of python 3 behavior
def __ne__(self, other):
ret = self.__eq__(other)
if ret is NotImplemented:
return NotImplemented
return not ret


RGB_equivalence = lambda c1, c2: c1.hex_l == c2.hex_l
HSL_equivalence = lambda c1, c2: c1._hsl == c2._hsl
Expand Down

0 comments on commit 8a6d439

Please sign in to comment.