Issue2367

classification
Title: Jython ignores custom __eq__ when hashing dict subclasses
Type: behaviour Severity: major
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.2
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: clevy, santa4nt, zyasoft
Priority: Keywords: patch

Created on 2015-06-10.19:33:20 by clevy, last changed 2016-02-15.18:54:11 by zyasoft.

Files
File name Uploaded Description Edit Remove
jythonbug.py clevy, 2015-06-10.19:33:18
issue2367.patch santa4nt, 2015-06-19.18:58:29
Messages
msg10106 (view) Author: Caleb Levy (clevy) Date: 2015-06-10.19:33:18
Take two subclasses of dict which define __hash__ and __eq__ (for example, we want to create an ImmutableMap) so that their hashes are equal, and dict.__eq__(dict1, dict2) returns True, but the objects are NOT equal due to their custom __eq__.

When using them BOTH as dictionary keys, Jython ignores the custom __eq__ upon hash collision and simply overwrites one key with the other. Note from the included tests that a hash collision is NOT the cause; if dict.__eq__(d1, d2) is False, both will still be used as keys.

This problem does not show up when inserting from list, tuple, object or any other classes I have tried.

Of the included unit tests, "test_distinct_in_set" and "test_distinct_as_keys" fail in Jython alone; the rest pass in Jython, CPython 2 and 3, and PyPy 2 and 3.
msg10107 (view) Author: Caleb Levy (clevy) Date: 2015-06-10.19:38:23
Not sure how to edit a submission, as I have not used this tracker before. Anyway, it should say "inheriting" instead of inserting in the third paragraph.
msg10124 (view) Author: Santoso Wijaya (santa4nt) Date: 2015-06-18.23:13:04
Additionally:

a = Dict1
b = Dict2

>>> a.__eq__(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unbound method __eq__() must be called with Dict1 instance as first argument (got type instance instead)
msg10125 (view) Author: Santoso Wijaya (santa4nt) Date: 2015-06-19.02:59:31
First draft of a patch that addressed this. I tested this with a version of the sample jythonbug.py, but not yet regressed.

Thoughts?
msg10743 (view) Author: Jim Baker (zyasoft) Date: 2016-02-15.18:54:10
This bug and possible resolution didn't get the triage it needed in 2.7.1. Defer to 2.7.2 for a fresh look.
History
Date User Action Args
2016-02-15 18:54:11zyasoftsetmessages: + msg10743
milestone: Jython 2.7.2
2015-06-19 18:58:30santa4ntsetfiles: + issue2367.patch
2015-06-19 18:58:17santa4ntsetfiles: - issue2367.patch
2015-06-19 02:59:33santa4ntsetfiles: + issue2367.patch
keywords: + patch
messages: + msg10125
2015-06-18 23:13:05santa4ntsetnosy: + santa4nt
messages: + msg10124
2015-06-10 21:36:16zyasoftsetnosy: + zyasoft
2015-06-10 19:38:24clevysetmessages: + msg10107
2015-06-10 19:33:20clevycreate