[New-bugs-announce] [issue28189] dictitems_contains swallows compare errors

Xiang Zhang report at bugs.python.org
Sat Sep 17 11:25:42 EDT 2016


New submission from Xiang Zhang:

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.

----------
components: Interpreter Core
files: dictitems_contains.patch
keywords: patch
messages: 276801
nosy: haypo, serhiy.storchaka, xiang.zhang
priority: normal
severity: normal
stage: patch review
status: open
title: dictitems_contains swallows compare errors
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file44717/dictitems_contains.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28189>
_______________________________________


More information about the New-bugs-announce mailing list