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
32 changes: 15 additions & 17 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,21 @@ def test_map_strict(self):
self.assertRaises(ValueError, tuple,
map(pack, (1, 2), (1, 2), 'abc', strict=True))

t1 = (None, object())
t2 = (object(), object())
t3 = (object(),)

self.assertRaises(ValueError, tuple,
map(pack, t1, 'a', strict=True))
self.assertRaises(ValueError, tuple,
map(pack, t1, t2, 'a', strict=True))
self.assertRaises(ValueError, tuple,
map(pack, t1, t2, t3, strict=True))
self.assertRaises(ValueError, tuple,
map(pack, 'a', t1, strict=True))
self.assertRaises(ValueError, tuple,
map(pack, 'a', t2, t3, strict=True))

def test_map_strict_iterators(self):
x = iter(range(5))
y = [0]
Expand Down Expand Up @@ -1457,23 +1472,6 @@ def __next__(self):
l8 = self.iter_error(map(pack, Iter(3), "AB", strict=True), ValueError)
self.assertEqual(l8, [(2, "A"), (1, "B")])

# gh-140517: fix refcount leak
def test_map_strict_noleak(self):
t1 = (None, object())
t2 = (object(), object())
t3 = (object(),)

self.assertRaises(ValueError, tuple,
map(pack, t1, 'a', strict=True))
self.assertRaises(ValueError, tuple,
map(pack, t1, t2, 'a', strict=True))
self.assertRaises(ValueError, tuple,
map(pack, t1, t2, t3, strict=True))
self.assertRaises(ValueError, tuple,
map(pack, 'a', t1, strict=True))
self.assertRaises(ValueError, tuple,
map(pack, 'a', t2, t3, strict=True))

def test_max(self):
self.assertEqual(max('123123'), '3')
self.assertEqual(max(1, 2, 3), 3)
Expand Down
6 changes: 4 additions & 2 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ map_next(PyObject *self)
if (PyErr_Occurred()) {
if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
// next() on argument i raised an exception (not StopIteration)
// result is NULL;
assert(result == NULL);
goto exit;
}
PyErr_Clear();
Expand Down Expand Up @@ -1549,14 +1549,16 @@ map_next(PyObject *self)
if (PyErr_Occurred()) {
if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
// next() on argument i raised an exception (not StopIteration)
// result is NULL;
assert(result == NULL);
goto exit;
}
PyErr_Clear();
}
// Argument i is exhausted. So far so good...
}
// All arguments are exhausted. Success!
assert(result == NULL);

exit:
for (i=0; i < nargs; i++) {
Py_DECREF(stack[i]);
Expand Down
Loading