Skip to content

Commit

Permalink
gh-101326: Fix regression when passing None to FutureIter.throw (#101327
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hauntsaninja authored and iritkatriel committed Jan 25, 2023
1 parent 97081c9 commit a725a19
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ def test_future_iter_throw(self):
Exception, Exception("elephant"), 32)
self.assertRaises(TypeError, fi.throw,
Exception("elephant"), Exception("elephant"))
# https://github.com/python/cpython/issues/101326
self.assertRaises(ValueError, fi.throw, ValueError, None, None)
self.assertRaises(TypeError, fi.throw, list)

def test_future_del_collect(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regression when passing ``None`` as second or third argument to ``FutureIter.throw``.
7 changes: 6 additions & 1 deletion Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,12 @@ FutureIter_throw(futureiterobject *self, PyObject *const *args, Py_ssize_t nargs
val = args[1];
}

if (tb != NULL && !PyTraceBack_Check(tb)) {
if (val == Py_None) {
val = NULL;
}
if (tb == Py_None ) {
tb = NULL;
} else if (tb != NULL && !PyTraceBack_Check(tb)) {
PyErr_SetString(PyExc_TypeError, "throw() third argument must be a traceback");
return NULL;
}
Expand Down

0 comments on commit a725a19

Please sign in to comment.