After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 519631 - fix comparison between enum values of different types
fix comparison between enum values of different types
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2008-02-29 21:30 UTC by Paul Pogonyshev
Modified: 2008-03-24 18:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
trivial patch (569 bytes, patch)
2008-02-29 21:30 UTC, Paul Pogonyshev
none Details | Review
patch with more useful warning message (846 bytes, patch)
2008-02-29 21:42 UTC, Paul Pogonyshev
committed Details | Review

Description Paul Pogonyshev 2008-02-29 21:30:05 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):
  • File "<stdin>", line 1 in <module>
SystemError: error return without exception set

After:
>>> import gtk
>>> gtk.JUSTIFY_LEFT == gtk.UNIT_POINTS
__main__:1: Warning: comparing different enum types
False
Comment 1 Paul Pogonyshev 2008-02-29 21:30:44 UTC
Created attachment 106298 [details] [review]
trivial patch
Comment 2 Paul Pogonyshev 2008-02-29 21:34:22 UTC
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).
Comment 3 Johan (not receiving bugmail) Dahlin 2008-02-29 21:36:41 UTC
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.
Comment 4 Paul Pogonyshev 2008-02-29 21:42:30 UTC
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 5 Johan (not receiving bugmail) Dahlin 2008-03-24 18:29:03 UTC
Comment on attachment 106299 [details] [review]
patch with more useful warning message

looks good
Comment 6 Paul Pogonyshev 2008-03-24 18:39:08 UTC
Sending        ChangeLog
Sending        gobject/pygenum.c
Transmitting file data ..
Committed revision 755.