GNOME Bugzilla – Bug 519631
fix comparison between enum values of different types
Last modified: 2008-03-24 18:39:08 UTC
Currently, pyg_enum_richcompare both issues a warning _and_ raises an exception (in an invalid way, btw) upon comparing different enum types. This trivial patch fixes it and only leaves the warning in place. Before: >>> import gtk >>> gtk.JUSTIFY_LEFT == gtk.UNIT_POINTS __main__:1: Warning: comparing different enum types Traceback (most recent call last):
+ Trace 190891
After: >>> import gtk >>> gtk.JUSTIFY_LEFT == gtk.UNIT_POINTS __main__:1: Warning: comparing different enum types False
Created attachment 106298 [details] [review] trivial patch
Just as an explanation: it results in a == b having the same value as int(a) == int(b) except that it gives a warning at runtime. Alternative sane option is to issue a warning, but return not int(a) == int(b) but NotImplemented (which would actually always result in False).
I think issuing a warning is fine, as long as you can easily see in a program where it's done, eg filename+line number. Perhaps the error message can be improved to mention the types you're trying to compare.
Created attachment 106299 [details] [review] patch with more useful warning message >>> import gtk >>> gtk.JUSTIFY_LEFT == gtk.UNIT_POINTS __main__:1: Warning: comparing different enum types: GtkJustification and GtkUnit False
Comment on attachment 106299 [details] [review] patch with more useful warning message looks good
Sending ChangeLog Sending gobject/pygenum.c Transmitting file data .. Committed revision 755.