From 9137d92f67a6d50782e199ca6d6558c1ea6015e2 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 13 Dec 2015 22:53:48 -0500 Subject: All data classes now support !=, == and str(obj). --- discord/colour.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'discord/colour.py') diff --git a/discord/colour.py b/discord/colour.py index 169e6a04..0b63a608 100644 --- a/discord/colour.py +++ b/discord/colour.py @@ -32,13 +32,15 @@ class Colour(object): Supported operations: - +-----------+--------------------------------------+ - | Operation | Description | - +===========+======================================+ - | x == y | Checks if two colours are equal. | - +-----------+--------------------------------------+ - | x != y | Checks if two colours are not equal. | - +-----------+--------------------------------------+ + +-----------+----------------------------------------+ + | Operation | Description | + +===========+========================================+ + | x == y | Checks if two colours are equal. | + +-----------+----------------------------------------+ + | x != y | Checks if two colours are not equal. | + +-----------+----------------------------------------+ + | str(x) | Returns the hex format for the colour. | + +-----------+----------------------------------------+ Attributes ------------ @@ -53,10 +55,13 @@ class Colour(object): return (self.value >> (8 * byte)) & 0xff def __eq__(self, other): - return self.value == getattr(other, 'value', None) + return isinstance(other, Colour) and self.value == other.value def __ne__(self, other): - return isinstance(other, Colour) and self.value != other.value + return not self.__eq__(other) + + def __str__(self): + return '#' + format(self.value, 'x') @property def r(self): -- cgit v1.2.3