]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101326: Fix regression when passing None to FutureIter.throw (#101327)
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>
Wed, 25 Jan 2023 20:01:01 +0000 (12:01 -0800)
committerGitHub <noreply@github.com>
Wed, 25 Jan 2023 20:01:01 +0000 (12:01 -0800)
Lib/test/test_asyncio/test_futures.py
Misc/NEWS.d/next/Library/2023-01-25-18-07-20.gh-issue-101326.KL4SFv.rst [new file with mode: 0644]
Modules/_asynciomodule.c

index 56b0b864de2ddf3dfa7e5228322760ee7b6b1ed9..2184b2091f84eed567e81502178ab1a4d143178a 100644 (file)
@@ -612,6 +612,8 @@ class BaseFutureTests:
                             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):
diff --git a/Misc/NEWS.d/next/Library/2023-01-25-18-07-20.gh-issue-101326.KL4SFv.rst b/Misc/NEWS.d/next/Library/2023-01-25-18-07-20.gh-issue-101326.KL4SFv.rst
new file mode 100644 (file)
index 0000000..54b69b9
--- /dev/null
@@ -0,0 +1 @@
+Fix regression when passing ``None`` as second or third argument to ``FutureIter.throw``.
index 6fe4ca469475263133b60acb89266e931412406d..055dded05431dfa750895ce881eac41ed7c7622c 100644 (file)
@@ -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;
     }