Skip to content

Commit

Permalink
fix on py3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 12, 2024
1 parent ccea747 commit cfafba0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tests/test_taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,16 @@ async def in_task_group(task_status: TaskStatus[None]) -> None:
assert not tg.cancel_scope.cancel_called


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

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

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


async def test_exception_refcycles_direct() -> None:
"""Test that TaskGroup doesn't keep a reference to the raised ExceptionGroup"""
tg = create_task_group()
Expand All @@ -1564,7 +1574,7 @@ class _Done(Exception):
exc = e

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


async def test_exception_refcycles_errors() -> None:
Expand All @@ -1582,7 +1592,7 @@ class _Done(Exception):
exc = excs.exceptions[0]

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


async def test_exception_refcycles_parent_task() -> None:
Expand All @@ -1604,7 +1614,7 @@ async def coro_fn() -> None:
exc = excs.exceptions[0].exceptions[0]

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


async def test_exception_refcycles_propagate_cancellation_error() -> None:
Expand All @@ -1622,7 +1632,7 @@ async def test_exception_refcycles_propagate_cancellation_error() -> None:
raise

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


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

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


class TestTaskStatusTyping:
Expand Down

0 comments on commit cfafba0

Please sign in to comment.