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

hauntsaninja webhook-mailer at python.org
Wed Jan 25 16:01:20 EST 2023


https://github.com/python/cpython/commit/cd0fe5ba09df65bdee90738129b7315a936b83fb
commit: cd0fe5ba09df65bdee90738129b7315a936b83fb
branch: 3.11
author: Shantanu <12621235+hauntsaninja at users.noreply.github.com>
committer: hauntsaninja <12621235+hauntsaninja at users.noreply.github.com>
date: 2023-01-25T13:01:13-08:00
summary:

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

(cherry picked from commit a178ba82bfe2f2fb6f6ff0e67cb734fd7c4321e3)

Co-authored-by: Shantanu <12621235+hauntsaninja at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2023-01-25-18-07-20.gh-issue-101326.KL4SFv.rst
M Lib/test/test_asyncio/test_futures.py
M Modules/_asynciomodule.c

diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index 987772e0b196..c6aad824c78d 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -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):
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
index 000000000000..54b69b943091
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-01-25-18-07-20.gh-issue-101326.KL4SFv.rst
@@ -0,0 +1 @@
+Fix regression when passing ``None`` as second or third argument to ``FutureIter.throw``.
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 40f1f80be447..b2fef017050b 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -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;
     }



More information about the Python-checkins mailing list