8000 gh-101326: Fix regression when passing None to FutureIter.throw (#101… · python/cpython@a178ba8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a178ba8

Browse files
authored
gh-101326: Fix regression when passing None to FutureIter.throw (#101327)
1 parent 952a1d9 commit a178ba8

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Lib/test/test_asyncio/test_futures.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ def test_future_iter_throw(self):
612612
Exception, Exception("elephant"), 32)
613613
self.assertRaises(TypeError, fi.throw,
614614
Exception("elephant"), Exception("elephant"))
615+
# https://github.com/python/cpython/issues/101326
616+
self.assertRaises(ValueError, fi.throw, ValueError, None, None)
615617
self.assertRaises(TypeError, fi.throw, list)
616618

617619
def test_future_del_collect(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix regression when passing ``None`` as second or third argument to ``FutureIter.throw``.

Modules/_asynciomodule.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,12 @@ FutureIter_throw(futureiterobject *self, PyObject *const *args, Py_ssize_t nargs
16941694
val = args[1];
16951695
}
16961696

1697-
if (tb != NULL && !PyTraceBack_Check(tb)) {
1697+
if (val == Py_None) {
1698+
val = NULL;
1699+
}
1700+
if (tb == Py_None ) {
1701+
tb = NULL;
1702+
} else if (tb != NULL && !PyTraceBack_Check(tb)) {
16981703
PyErr_SetString(PyExc_TypeError, "throw() third argument must be a traceback");
16991704
return NULL;
17001705
}

0 commit comments

Comments
 (0)
0