Skip to content

Commit 5291130

Browse files
committed
fix on py3.9 and py3.10
1 parent ccea747 commit 5291130

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tests/test_taskgroups.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,16 @@ async def in_task_group(task_status: TaskStatus[None]) -> None:
15491549
assert not tg.cancel_scope.cancel_called
15501550

15511551

1552+
if sys.version_info <= (3, 11):
1553+
1554+
def no_other_refs() -> list[object]:
1555+
return [sys._getframe(1)]
1556+
else:
1557+
1558+
def no_other_refs() -> list[object]:
1559+
return []
1560+
1561+
15521562
async def test_exception_refcycles_direct() -> None:
15531563
"""Test that TaskGroup doesn't keep a reference to the raised ExceptionGroup"""
15541564
tg = create_task_group()
@@ -1564,7 +1574,7 @@ class _Done(Exception):
15641574
exc = e
15651575

15661576
assert exc is not None
1567-
assert gc.get_referrers(exc) == []
1577+
assert gc.get_referrers(exc) == no_other_refs()
15681578

15691579

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

15841594
assert isinstance(exc, _Done)
1585-
assert gc.get_referrers(exc) == []
1595+
assert gc.get_referrers(exc) == no_other_refs()
15861596

15871597

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

16061616
assert isinstance(exc, _Done)
1607-
assert gc.get_referrers(exc) == []
1617+
assert gc.get_referrers(exc) == no_other_refs()
16081618

16091619

16101620
async def test_exception_refcycles_propagate_cancellation_error() -> None:
@@ -1622,7 +1632,7 @@ async def test_exception_refcycles_propagate_cancellation_error() -> None:
16221632
raise
16231633

16241634
assert isinstance(exc, get_cancelled_exc_class())
1625-
assert gc.get_referrers(exc) == []
1635+
assert gc.get_referrers(exc) == no_other_refs()
16261636

16271637

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

16431653
assert isinstance(exc, MyKeyboardInterrupt)
1644-
assert gc.get_referrers(exc) == []
1654+
assert gc.get_referrers(exc) == no_other_refs()
16451655

16461656

16471657
class TestTaskStatusTyping:

0 commit comments

Comments
 (0)