[3.11] gh-101326: Fix regression when passing None to FutureIter.throw (GH-101327) (#101328)

(cherry picked from commit a178ba82bf)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
This commit is contained in:
Shantanu 2023-01-25 13:01:13 -08:00 committed by GitHub
parent 5a8ed019f9
commit cd0fe5ba09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -607,6 +607,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):

View File

@ -0,0 +1 @@
Fix regression when passing ``None`` as second or third argument to ``FutureIter.throw``.

View File

@ -1666,7 +1666,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;
}