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 527212 - types with well-defined equality semantics are not properly comparable
types with well-defined equality semantics are not properly comparable
Status: RESOLVED WONTFIX
Product: pygtk
Classification: Bindings
Component: general
Git Master
Other All
: Normal enhancement
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
gnome[unmaintained]
Depends on:
Blocks:
 
 
Reported: 2008-04-09 19:23 UTC by Paul Pogonyshev
Modified: 2018-08-17 13:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch for gtk.gdk.Color, gtk.gdk.Region and gtk.gdk.Rectangle (3.86 KB, patch)
2008-04-11 20:48 UTC, Paul Pogonyshev
none Details | Review
example, demonstrating why mutable classes must not be hashable (643 bytes, text/plain)
2008-07-03 16:53 UTC, Paul Pogonyshev
  Details
patch for gtk.gdk.Color, gtk.gdk.Region and gtk.gdk.Rectangle + tests and docs (14.20 KB, patch)
2008-07-31 20:44 UTC, Paul Pogonyshev
none Details | Review
patch for gtk.gdk.Color, gtk.gdk.Region and gtk.gdk.Rectangle + tests and docs (13.58 KB, patch)
2008-07-31 20:46 UTC, Paul Pogonyshev
committed Details | Review

Description Paul Pogonyshev 2008-04-09 19:23:00 UTC
>>> a = gtk.gdk.Color (0, 0, 0)
>>> b = gtk.gdk.Color (0, 0, 0)
>>> a == b
False

To me this looks like a bug, but I file it with 'enhancement' severity.  Likely applies to some other types like rectangles as well.
Comment 1 Paul Pogonyshev 2008-04-11 20:48:53 UTC
Created attachment 109083 [details] [review]
patch for gtk.gdk.Color, gtk.gdk.Region and gtk.gdk.Rectangle

Adds __eq__/__ne__ for 3 types in gtk.gdk.  Returns NotImplemented for ordering comparison.  That yields weird results in Python 2.x, but I believe we should follow suit.  AFAIK in Python 3.0 it becomes more strict and I suspect NotImplemented will get transformed into an exception there (obviously cannot test PyGTK on 3.0, too lazy to test with anything else.)
Comment 2 Paul Pogonyshev 2008-04-14 19:24:12 UTC
One unfortunate thing: now these objects compare by identity and are hashable.  In this case hashing is fine, though comparison by identity is quite meaningless anyway.  However, if we switch to comparing by contents (as would make sense), by Python rules the objects _must_ become unhashable, because they are mutable.  So, we have quite significant backward incompatibility here...

Alternatively, we can make rectangles and colors immutable, but that is probably even more of a compatibility break.
Comment 3 Paul Pogonyshev 2008-07-03 16:50:31 UTC
One more idea is to have gtk.gdk.Rectangle and gtk.gdk.FrozenRectangle, much as built-in 'set' and 'frozenset' in Python.  First would be like the current type, except that it would be properly comparable and (hence) non-hashable.  Second would be like plain rectangles, except that immutable and (hence) hashable.  (I'm speaking about rectangles here, but we can generalize this to other types as well.)

Note that in Python 'set' and 'frozenset' are not a superclass of each other.  This is, strictly speaking, correct as neither provides all functionality of the other.  However, this makes writing isinstance() checks more difficult: you should write isinstance (foo, (set, frozenset)) to catch both cases.
Comment 4 Paul Pogonyshev 2008-07-03 16:53:58 UTC
Created attachment 113935 [details]
example, demonstrating why mutable classes must not be hashable

This is just a demonstration why mutable classes (in which mutations can affect equality result, I mean) must not be hashable.  While you'd expect it output True 4 times, it only does it 2 times.  After the mutation, set becomes broken.
Comment 5 Paul Pogonyshev 2008-07-31 20:44:51 UTC
Created attachment 115640 [details] [review]
patch for gtk.gdk.Color, gtk.gdk.Region and gtk.gdk.Rectangle + tests and docs

The same (functionally) patch, with tests for gtk.gdk.Color and gtk.gdk.Rectnagle and documentation changes for all three classes added.  I also moved misplaced test for gtk.gdk.Color constructor.
Comment 6 Paul Pogonyshev 2008-07-31 20:46:46 UTC
Created attachment 115641 [details] [review]
patch for gtk.gdk.Color, gtk.gdk.Region and gtk.gdk.Rectangle + tests and docs

Forgot to remove chunk disabling the now-failing treeview test (must be a bug in GTK+).
Comment 7 Paul Pogonyshev 2008-08-02 16:09:47 UTC
Committed the first patch (approved by Johan on IRC).  I keep the bug open for now, as there are probably more types in need of similar changes.

Sending        ChangeLog
Sending        docs/reference/ChangeLog
Sending        docs/reference/pygtk-gdkcolor.xml
Sending        docs/reference/pygtk-gdkrectangle.xml
Sending        docs/reference/pygtk-gdkregion.xml
Sending        gtk/gdk.override
Sending        gtk/gdkcolor.override
Sending        gtk/gdkrectangle.override
Sending        tests/Makefile.am
Adding         tests/test_color.py
Sending        tests/test_conversion.py
Adding         tests/test_rectangle.py
Transmitting file data ............
Committed revision 3014.
Comment 8 André Klapper 2018-08-17 13:35:25 UTC
pygtk is not under active development anymore and had its last code changes
in 2013. Its codebase has been archived:
https://gitlab.gnome.org/Archive/pygtk/commits/master

PyGObject at https://gitlab.gnome.org/GNOME/pygobject is its successor. See https://pygobject.readthedocs.io/en/latest/guide/porting.html for porting info.

Closing this report as WONTFIX as part of Bugzilla Housekeeping to reflect
reality. Feel free to open a task in GNOME Gitlab if the issue described in this task still applies to a recent version of PyGObject. Thanks!