Skip to content

Commit 79606d6

Browse files
committed
fix incompatability with pythongh-124392
1 parent 050cef9 commit 79606d6

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Lib/test/test_asyncio/test_taskgroups.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Adapted with permission from the EdgeDB project;
22
# license: PSFL.
33

4+
import sys
45
import gc
56
import asyncio
67
import contextvars
@@ -28,6 +29,15 @@ def get_error_types(eg):
2829
return {type(exc) for exc in eg.exceptions}
2930

3031

32+
def no_other_refs():
33+
# due to gh-124392 coroutines now refer to their locals
34+
coro = asyncio.current_task().get_coro()
35+
frame = sys._getframe(1)
36+
while coro.cr_frame != frame:
37+
coro = coro.cr_await
38+
return [coro]
39+
40+
3141
class TestTaskGroup(unittest.IsolatedAsyncioTestCase):
3242

3343
async def test_taskgroup_01(self):
@@ -913,7 +923,7 @@ class _Done(Exception):
913923
exc = e
914924

915925
self.assertIsNotNone(exc)
916-
self.assertListEqual(gc.get_referrers(exc), [])
926+
self.assertListEqual(gc.get_referrers(exc), no_other_refs())
917927

918928

919929
async def test_exception_refcycles_errors(self):
@@ -931,7 +941,7 @@ class _Done(Exception):
931941
exc = excs.exceptions[0]
932942

933943
self.assertIsInstance(exc, _Done)
934-
self.assertListEqual(gc.get_referrers(exc), [])
944+
self.assertListEqual(gc.get_referrers(exc), no_other_refs())
935945

936946

937947
async def test_exception_refcycles_parent_task(self):
@@ -953,7 +963,7 @@ async def coro_fn():
953963
exc = excs.exceptions[0].exceptions[0]
954964

955965
self.assertIsInstance(exc, _Done)
956-
self.assertListEqual(gc.get_referrers(exc), [])
966+
self.assertListEqual(gc.get_referrers(exc), no_other_refs())
957967

958968
async def test_exception_refcycles_propagate_cancellation_error(self):
959969
"""Test that TaskGroup deletes propagate_cancellation_error"""
@@ -968,7 +978,7 @@ async def test_exception_refcycles_propagate_cancellation_error(self):
968978
exc = e.__cause__
969979

970980
self.assertIsInstance(exc, asyncio.CancelledError)
971-
self.assertListEqual(gc.get_referrers(exc), [])
981+
self.assertListEqual(gc.get_referrers(exc), no_other_refs())
972982

973983
async def test_exception_refcycles_base_error(self):
974984
"""Test that TaskGroup deletes self._base_error"""
@@ -985,7 +995,7 @@ class MyKeyboardInterrupt(KeyboardInterrupt):
985995
exc = e
986996

987997
self.assertIsNotNone(exc)
988-
self.assertListEqual(gc.get_referrers(exc), [])
998+
self.assertListEqual(gc.get_referrers(exc), no_other_refs())
989999

9901000

9911001
if __name__ == "__main__":

0 commit comments

Comments
 (0)