Issue2522

classification
Title: defaultdict.__getitem__(unhashable) raises KeyError instead of TypeError
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.7
Milestone: Jython 2.7.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: stefan.richthofer Nosy List: buelgsk8er, stefan.richthofer, zyasoft
Priority: Keywords:

Created on 2016-09-25.09:01:58 by buelgsk8er, last changed 2017-02-27.04:43:55 by zyasoft.

Messages
msg10955 (view) Author: (buelgsk8er) Date: 2016-09-25.09:01:57
How to reproduce
================

in CPython 2.7:

>>> from collections import defaultdict
>>> dict().__getitem__({})
TypeError: unhashable type: 'dict'
>>> dict().__setitem__({}, None)
TypeError: unhashable type: 'dict'
>>> defaultdict(int).__setitem__({}, None)
TypeError: unhashable type: 'dict'
>>> defaultdict(int).__getitem__({})
TypeError: unhashable type: 'dict'


in Jython 2.7.1b3

>>> UNHASHABLE = {}
>>> dict().__getitem__(UNHASHABLE)
TypeError: unhashable type: 'dict'
>>> dict().__setitem__({}, None)
TypeError: unhashable type: 'dict'
>>> defaultdict(int).__setitem__({}, None)
TypeError: unhashable type: 'dict'
>>> defaultdict(int).__getitem__({})
KeyError: {}
msg10956 (view) Author: (buelgsk8er) Date: 2016-09-25.09:51:31
Background
==========

zope.interface relies this behavior to detect unhashable components, i.e. instances of pyramid.config.Settings which derives from 'dict' directly.

relevant source codes:
https://github.com/zopefoundation/zope.interface/blob/master/src/zope/interface/registry.py#L128
https://github.com/zopefoundation/zope.interface/blob/master/src/zope/interface/registry.py#L152
https://github.com/Pylons/pyramid/blob/master/pyramid/config/settings.py#L58
msg10958 (view) Author: (buelgsk8er) Date: 2016-09-25.20:20:55
relevant Pull Request:
https://github.com/jythontools/jython/pull/48

relevant Travis CI build:
https://travis-ci.org/jythontools/jython/builds/162613271 (it fails but seems like not related with this patch.)
msg10961 (view) Author: Jim Baker (zyasoft) Date: 2016-09-26.16:37:50
Similar comments to #2523

re the CI failures - this is because of some annoying noise that certain socket tests are emitting; see #2517
msg11015 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-01-12.13:28:09
Merged PR #48 github.com/jythontools/jython/pull/48 as of github.com/jythontools/jython/commit/1eb9dc0c48d5017ca621035037fd390ece346fb4.

Thanks to buelgsk8er: If you reconsider your statement in http://bugs.jython.org/issue2523 regarding ACKNOWLEDGEMENTS-file, please tell me any time and we will add you.
History
Date User Action Args
2017-02-27 04:43:55zyasoftsetstatus: pending -> closed
2017-01-12 13:28:10stefan.richthofersetstatus: open -> pending
nosy: + stefan.richthofer
messages: + msg11015
assignee: stefan.richthofer
milestone: Jython 2.7.2 -> Jython 2.7.1
resolution: fixed
2016-09-30 16:19:06zyasoftsetmilestone: Jython 2.7.2
2016-09-26 16:37:50zyasoftsetnosy: + zyasoft
messages: + msg10961
2016-09-25 20:20:55buelgsk8ersetmessages: + msg10958
2016-09-25 09:51:32buelgsk8ersetmessages: + msg10956
2016-09-25 09:01:58buelgsk8ercreate