mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
bpo-38202: Fix a crash in dict_view & non-itearble. (GH-16241)
This commit is contained in:
parent
793cb85437
commit
b16e382c44
2 changed files with 23 additions and 0 deletions
|
|
@ -227,6 +227,25 @@ def test_set_operations_with_iterator(self):
|
|||
self.assertEqual(items | iter([(1, 2)]), {(1, 2), (3, 4)})
|
||||
self.assertEqual(items - iter([(1, 2)]), {(3, 4)})
|
||||
|
||||
def test_set_operations_with_noniterable(self):
|
||||
with self.assertRaises(TypeError):
|
||||
{}.keys() & 1
|
||||
with self.assertRaises(TypeError):
|
||||
{}.keys() | 1
|
||||
with self.assertRaises(TypeError):
|
||||
{}.keys() ^ 1
|
||||
with self.assertRaises(TypeError):
|
||||
{}.keys() - 1
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
{}.items() & 1
|
||||
with self.assertRaises(TypeError):
|
||||
{}.items() | 1
|
||||
with self.assertRaises(TypeError):
|
||||
{}.items() ^ 1
|
||||
with self.assertRaises(TypeError):
|
||||
{}.items() - 1
|
||||
|
||||
def test_recursive_repr(self):
|
||||
d = {}
|
||||
d[42] = d.values()
|
||||
|
|
|
|||
|
|
@ -4227,6 +4227,10 @@ _PyDictView_Intersect(PyObject* self, PyObject *other)
|
|||
return NULL;
|
||||
|
||||
it = PyObject_GetIter(other);
|
||||
if (it == NULL) {
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyDictKeys_Check(self)) {
|
||||
dict_contains = dictkeys_contains;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue