GNOME Bugzilla – Bug 647725
hash() and cmp() on GLib.Variant objects are broken
Last modified: 2012-02-04 14:45:49 UTC
GLib.Variant.__hash__ does not return the same number for identical data >>> a = GLib.Variant("(b)", (False,)) >>> b = GLib.Variant("(b)", (False,)) >>> hash(a) 38947056 >>> hash(b) 38947344 >>> a == b False This behaviour is completely wrong, as it breaks dicts, sets and other datastructures because __eq__ now always returns False. In addition, this also breaks cmp() which relies on __hash__ for comparisons when __cmp__ is not defined. >>> a = GLib.Variant("i", 1) >>> b = GLib.Variant("i", 1) >>> a > b False >>> a < b True >>> a == b False >>> hash(a) 20014848 >>> hash(b) 20014944
Created attachment 206311 [details] [review] Implement __hash__, __eq__, __ne__ This allows Variant types to be used in comparisons (==, !=) and in sets/frozensets/dicts. This patch needs the patch from bug 647723 before it can be applied cleanly.
Review of attachment 206311 [details] [review]: Thanks for your work, looks good.
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.