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

Created on 2015-06-10.19:33:20 by clevy, last changed 2018-03-22.07:50:53 by jeff.allen.

File name Uploaded Description Edit Remove clevy, 2015-06-10.19:33:18
issue2367.patch santa4nt, 2015-06-19.18:58:29
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

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, but not yet regressed.

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.
msg11842 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-22.07:50:31
... and not for 2.7.2 either.
Date User Action Args
2018-03-22 07:50:53jeff.allensetpriority: normal
2018-03-22 07:50:31jeff.allensetnosy: + jeff.allen
messages: + msg11842
milestone: Jython 2.7.2 ->
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