#11383: Color('red') == Color('red') returns False
------------------------+---------------------------------------------------
Reporter: slabbe | Owner: slabbe
Type: defect | Status: needs_work
Priority: major | Milestone: sage-4.7.2
Component: graphics | Keywords: beginner, sd31
Work_issues: | Upstream: N/A
Reviewer: | Author: Ryan Grout
Merged: | Dependencies:
------------------------+---------------------------------------------------
Comment(by jhpalmieri):
Why not change the hash method? It could be something like
{{{
#!python
def __hash__(self):
return hash(self.__rgb)
}}}
(This would need doctests, obviously.)
Alternatively, what about a patch like this:
{{{
#!diff
diff --git a/sage/plot/colors.py b/sage/plot/colors.py
--- a/sage/plot/colors.py
+++ b/sage/plot/colors.py
@@ -364,8 +364,15 @@ def rgbcolor(c, space='rgb'):
# For backward compatibility.
to_mpl_color = rgbcolor
+from sage.structure.unique_representation import UniqueRepresentation
-class Color(object):
+class Color(UniqueRepresentation):
+ @staticmethod
+ def __classcall__(self, r='#0000ff', g=None, b=None, space='rgb'):
+ if isinstance(r, list):
+ r = tuple(r)
+ return super(Color, self).__classcall__(self, r, g, b, space)
+
def __init__(self, r='#0000ff', g=None, b=None, space='rgb'):
"""
An Red-Green-Blue (RGB) color model color object. For most
}}}
(The `__classcall__` method might need a bit more cleaning up, and it
needs documentation and doctests.)
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11383#comment:11>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.