[3.10] bpo-46009: Do not exhaust generator when send() method raises (GH-29986). (GH-29988)

* [3.10] bpo-46009: Do not exhaust generator when send() method raises (GH-29986).
(cherry picked from commit 69806b9516)

Co-authored-by: Mark Shannon <mark@hotpy.org>

* Rename variable after cherry-pick.

* Add NULL check.
This commit is contained in:
Mark Shannon 2021-12-08 14:46:32 +00:00 committed by GitHub
parent cca3004f64
commit 99c72326d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 21 deletions

View file

@ -161,6 +161,14 @@ def f():
with self.assertRaises((TypeError, pickle.PicklingError)):
pickle.dumps(g, proto)
def test_send_non_none_to_new_gen(self):
def f():
yield 1
g = f()
with self.assertRaises(TypeError):
g.send(0)
self.assertEqual(next(g), 1)
class ExceptionTest(unittest.TestCase):
# Tests for the issue #23353: check that the currently handled exception