8000 [3.11] gh-101326: Fix regression when passing None to FutureIter.thro… · python/cpython@cd0fe5b · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit cd0fe5b

Browse files
authored
[3.11] gh-101326: Fix regression when passing None to FutureIter.throw (GH-101327) (#101328)
(cherry picked from commit a178ba8) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
1 parent 5a8ed01 commit cd0fe5b

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
@@ -607,6 +607,8 @@ def test_future_iter_throw(self):
607607
Exception, Exception("elephant"), 32)
608608
self.assertRaises(TypeError, fi.throw,
609609
Exception("elephant"), Exception("elephant"))
610+
# https://github.com/python/cpython/issues/101326
611+
self.assertRaises(ValueError, fi.throw, ValueError, None, None)
610612
self.assertRaises(TypeError, fi.throw, list)
611613

612614
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
@@ -1666,7 +1666,12 @@ FutureIter_throw(futureiterobject *self, PyObject *const *args, Py_ssize_t nargs
16661666
val = args[1];
16671667
}
16681668

1669-
if (tb != NULL && !PyTraceBack_Check(tb)) {
1669+
if (val == Py_None) {
1670+
val = NULL;
1671+
}
1672+
if (tb == Py_None ) {
1673+
tb = NULL;
1674+
} else if (tb != NULL && !PyTraceBack_Check(tb)) {
16701675
PyErr_SetString(PyExc_TypeError, "throw() third argument must be a traceback");
16711676
return NULL;
16721677
}

0 commit comments

Comments
 (0)
0