]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Port regression test for issue GH-93592 (GH-96208)
authorKristján Valur Jónsson <sweskman@gmail.com>
Fri, 26 Aug 2022 14:07:31 +0000 (14:07 +0000)
committerGitHub <noreply@github.com>
Fri, 26 Aug 2022 14:07:31 +0000 (15:07 +0100)
Lib/test/test_coroutines.py

index dba5ceffaf1c03ee37eafc8eec6db4b6510eb999..8fff2d47c10fd5665ee2a5c9bca4f659c536de3c 100644 (file)
@@ -4,6 +4,7 @@ import inspect
 import pickle
 import sys
 import types
+import traceback
 import unittest
 import warnings
 from test import support
@@ -2207,6 +2208,29 @@ class CoroutineTest(unittest.TestCase):
         with self.assertWarns(RuntimeWarning):
             gen.cr_frame.clear()
 
+    def test_stack_in_coroutine_throw(self):
+        # Regression test for https://github.com/python/cpython/issues/93592
+        async def a():
+            return await b()
+
+        async def b():
+            return await c()
+
+        @types.coroutine
+        def c():
+            try:
+                # traceback.print_stack()
+                yield len(traceback.extract_stack())
+            except ZeroDivisionError:
+                # traceback.print_stack()
+                yield len(traceback.extract_stack())
+
+        coro = a()
+        len_send = coro.send(None)
+        len_throw = coro.throw(ZeroDivisionError)
+        # before fixing, visible stack from throw would be shorter than from send.
+        self.assertEqual(len_send, len_throw)
+
 
 @unittest.skipIf(
     support.is_emscripten or support.is_wasi,