classification
Title: dictitems_contains swallows compare errors
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: python-dev, rhettinger, serhiy.storchaka, vstinner, xiang.zhang
Priority: normal Keywords: patch

Created on 2016-09-17 15:25 by xiang.zhang, last changed 2016-09-19 04:51 by xiang.zhang. This issue is now closed.

Files
File name Uploaded Description Edit
dictitems_contains.patch xiang.zhang, 2016-09-17 15:25 review
Messages (4)
msg276801 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-09-17 15:25
Now, when compare errors raised during `in`, dict.keys(), dict.values() and set all propagate the errors. But dict.items() will swallow the errors(only key compare):

>>> class BadEq:
...     def __hash__(self):
...             return 7
...     def __eq__(self, other):
...             raise RuntimeError
... 
>>> k1, k2, v1, v2 = BadEq(), BadEq(), BadEq(), BadEq()
>>> d = {k1: v1}
>>> k2 in d.keys()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in __eq__
RuntimeError
>>> v2 in d.values()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in __eq__
RuntimeError
>>> k2 in {k1}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in __eq__
RuntimeError
>>> (k2, v2) in d.items()
False
>>> (k2, v1) in d.items()
False

dictitems_contains.patch tries to fix this.
msg276940 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-19 04:46
New changeset 2a9e0e869ca7 by Raymond Hettinger in branch '3.5':
Issue #28189: dictitems_contains no longer swallows compare errors.
https://hg.python.org/cpython/rev/2a9e0e869ca7
msg276941 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-09-19 04:50
Thanks for the patch.
msg276942 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-09-19 04:51
Thanks for the merge Raymond. :)
History
Date User Action Args
2016-09-19 04:51:41xiang.zhangsetmessages: + msg276942
stage: patch review -> resolved
2016-09-19 04:50:13rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg276941
2016-09-19 04:46:43python-devsetnosy: + python-dev
messages: + msg276940
2016-09-19 04:01:30rhettingersetassignee: rhettinger

nosy: + rhettinger
2016-09-17 15:25:42xiang.zhangcreate