Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
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
14 changes: 14 additions & 0 deletions colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

import hashlib
import re
import sys


##
## Some Constants
Expand Down Expand Up @@ -931,6 +933,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 +1099,12 @@ def __eq__(self, other):
return self.equality(self, other)
return NotImplemented

if sys.version_info[0] == 2:
## Note: intended to be a backport of python 3 behavior
def __ne__(self, other):
equal = self.__eq__(other)
return equal if equal is NotImplemented else not equal


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