Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_dictviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def intersection(self, other):
self.assertTrue(de.keys().isdisjoint(de.keys()))
self.assertTrue(de.keys().isdisjoint([1]))

def test_keys_set_operations_with_iterator(self):
origin = {1: 2, 3: 4}
self.assertEqual((origin.keys() & iter([1, 2])), {1})
self.assertEqual((origin.keys() | iter([1, 2])), {1, 2, 3})
self.assertEqual((origin.keys() ^ iter([1, 2])), {2, 3})

def test_items_set_operations(self):
d1 = {'a': 1, 'b': 2}
d2 = {'a': 2, 'b': 2}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove unecessary intersection and update set operation in dictview with
empty set. (Contributed by Dong-hee Na in :issue:`38210`.)
8 changes: 0 additions & 8 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4225,14 +4225,6 @@ _PyDictView_Intersect(PyObject* self, PyObject *other)

it = PyObject_GetIter(other);

_Py_IDENTIFIER(intersection_update);
tmp = _PyObject_CallMethodIdOneArg(result, &PyId_intersection_update, other);
if (tmp == NULL) {
Py_DECREF(result);
return NULL;
}
Py_DECREF(tmp);

if (PyDictKeys_Check(self)) {
dict_contains = dictkeys_contains;
}
Expand Down