Skip to content

bpo-38210: Remove intersection operation with empty set #16602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
10 changes: 10 additions & 0 deletions Lib/test/test_dictviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ def test_items_set_operations(self):
self.assertTrue(de.items().isdisjoint(de.items()))
self.assertTrue(de.items().isdisjoint([1]))

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

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

def test_recursive_repr(self):
d = {}
d[42] = d.values()
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