Skip to content

Commit

Permalink
fix no_other_refs on 3.14
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 21, 2024
1 parent a100eaf commit cd1b7ee
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions tests/test_taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,14 +1561,29 @@ async def in_task_group(task_status: TaskStatus[None]) -> None:
assert not tg.cancel_scope.cancel_called


if sys.version_info <= (3, 11):
if sys.version_info >= (3, 14):

def no_other_refs() -> list[object]:
return [sys._getframe(1)]
else:
async def no_other_refs() -> list[object]:
frame = sys._getframe(1)
coro = get_current_task().coro

async def get_coro_for_frame(*, task_status: TaskStatus[object]) -> None:
my_coro = coro
while my_coro.cr_frame is not frame:
my_coro = my_coro.cr_await
task_status.started(my_coro)

async with create_task_group() as tg:
return [await tg.start(get_coro_for_frame)]

def no_other_refs() -> list[object]:
elif sys.version_info >= (3, 11):

async def no_other_refs() -> list[object]:
return []
else:

async def no_other_refs() -> list[object]:
return [sys._getframe(1)]


@pytest.mark.skipif(
Expand Down Expand Up @@ -1599,7 +1614,7 @@ class _Done(Exception):
exc = e

assert exc is not None
assert gc.get_referrers(exc) == no_other_refs()
assert gc.get_referrers(exc) == await no_other_refs()

async def test_exception_refcycles_errors(self) -> None:
"""Test that TaskGroup deletes self._exceptions, and __aexit__ args"""
Expand All @@ -1616,7 +1631,7 @@ class _Done(Exception):
exc = excs.exceptions[0]

assert isinstance(exc, _Done)
assert gc.get_referrers(exc) == no_other_refs()
assert gc.get_referrers(exc) == await no_other_refs()

async def test_exception_refcycles_parent_task(self) -> None:
"""Test that TaskGroup's cancel_scope deletes self._host_task"""
Expand All @@ -1637,7 +1652,7 @@ async def coro_fn() -> None:
exc = excs.exceptions[0].exceptions[0]

assert isinstance(exc, _Done)
assert gc.get_referrers(exc) == no_other_refs()
assert gc.get_referrers(exc) == await no_other_refs()

async def test_exception_refcycles_propagate_cancellation_error(self) -> None:
"""Test that TaskGroup deletes cancelled_exc"""
Expand All @@ -1654,7 +1669,7 @@ async def test_exception_refcycles_propagate_cancellation_error(self) -> None:
raise

assert isinstance(exc, get_cancelled_exc_class())
assert gc.get_referrers(exc) == no_other_refs()
assert gc.get_referrers(exc) == await no_other_refs()

async def test_exception_refcycles_base_error(self) -> None:
"""
Expand All @@ -1677,7 +1692,7 @@ class MyKeyboardInterrupt(KeyboardInterrupt):
exc = excs.exceptions[0]

assert isinstance(exc, MyKeyboardInterrupt)
assert gc.get_referrers(exc) == no_other_refs()
assert gc.get_referrers(exc) == await no_other_refs()


class TestTaskStatusTyping:
Expand Down

0 comments on commit cd1b7ee

Please sign in to comment.