Hash of colors seems wrong

Consider the attached program. On my system (XP), the first print is True
(bgColor == wx.Colour(49, 106, 197)) but the second statement
(hash(bgColor) == hash(wx.Colour(49, 106, 197))) is False. Aren't the hash
values supposed to be equal when the items are equal?

wx-test17.py (1.1 KB)

···

--
Jeffrey Barish

The hash will only be equal if wx.Colour defines its __hash__ as a
function of its content. More likely is that __hash__ just isn't
defined, so the hash(color) is the same as id(color); which is the
default hash.

If you really want your colors to match up, don't use wx.Colour, use a
tuple (49,106,197). I believe that most places which would take a
wx.Colour would also take a 3-tuple instead, but I could be wrong (I
don't deal with colors much).

- Josiah

···

Jeffrey Barish <jeff_barish@earthlink.net> wrote:

Consider the attached program. On my system (XP), the first print is True
(bgColor == wx.Colour(49, 106, 197)) but the second statement
(hash(bgColor) == hash(wx.Colour(49, 106, 197))) is False. Aren't the hash
values supposed to be equal when the items are equal?

Josiah Carlson wrote:

If you really want your colors to match up, don't use wx.Colour, use a
tuple (49,106,197). I believe that most places which would take a
wx.Colour would also take a 3-tuple instead,

Yep. See http://wxpython.org/docs/api/wx.Colour-class.html

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!