[issue38210] Intersection of dict view with iterator returns empty set
Łukasz Langa
report at bugs.python.org
Wed Jul 14 12:24:13 EDT 2021
Łukasz Langa <lukasz at langa.pl> added the comment:
This caused an unintentional behavior change in the following code:
>>> {1: 2}.items() & {1: {2: 3}}.items()
set()
Before this change, Python 3.6 - 3.8 behaved like this instead:
>>> {1: 2}.items() & {1: {2: 3}}.items()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
Interestingly, this doesn't seem to have a negative effect on correctness as the silently omitted unhashable (k, v) pair is only omitted if it's different between the two dictionaries:
>>> {1: {2: 4}}.items() & {1: {2: 3}}.items()
set()
>>> {2: 1, 1: {2: 4}}.items() & {2: 1, 1: {2: 3}}.items()
{(2, 1)}
If it's the same, we still get an error in Python 3.9:
>>> {1: {2: 3}}.items() & {1: {2: 3}}.items()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
>>> {2: 1, 1: {2: 3}}.items() & {2: 1, 1: {2: 3}}.items()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
----------
nosy: +lukasz.langa
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38210>
_______________________________________
More information about the Python-bugs-list
mailing list