Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Commit 5dc83d9

Browse files
authored
asyncio: honor pending-task, unawaited, and get_referrers (RustPython#8689)
* asyncio: honor pending-task, unawaited, and get_referrers Report Task destructor as 'Task was destroyed but it is pending!'. Warn when a never-started coroutine is collected. Preserve signal() errno. Attribute generator-owned frame locals to the owner in gc.get_referrers. Remove the expectedFailure markers that now pass. Assisted-by: Grok:grok-4.6 * tests: drop expectedFailure after unawaited warning The never-started coroutine RuntimeWarning unblocks test_bpo_45813_1 and the AsyncMock assertNeverAwaited cases. Assisted-by: Grok:grok-4.6
1 parent 53f518e commit 5dc83d9

12 files changed

Lines changed: 30 additions & 95 deletions

File tree

‎Lib/test/test_asyncio/test_events.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ def tearDown(self):
273273
support.gc_collect()
274274
super().tearDown()
275275

276-
@unittest.expectedFailure # TODO: RUSTPYTHON; - RuntimeWarning for unawaited coroutine not triggered
277276
def test_run_until_complete_nesting(self):
278277
async def coro1():
279278
await asyncio.sleep(0)
@@ -560,7 +559,6 @@ def writer(data):
560559
r.close()
561560
self.assertEqual(read, data)
562561

563-
@unittest.expectedFailure # TODO: RUSTPYTHON; - signal handler implementation differs
564562
@unittest.skipUnless(hasattr(signal, 'SIGKILL'), 'No SIGKILL')
565563
def test_add_signal_handler(self):
566564
caught = 0

‎Lib/test/test_asyncio/test_futures.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,6 @@ def test_callbacks_copy(self):
734734
fut.remove_done_callback(f2)
735735
self.assertIsNone(fut._callbacks)
736736

737-
@unittest.expectedFailure # TODO: RUSTPYTHON; - gc.get_referents not implemented
738-
def test_future_iter_get_referents_segfault(self):
739-
return super().test_future_iter_get_referents_segfault()
740-
741737

742738
@unittest.skipUnless(hasattr(futures, '_CFuture'),
743739
'requires the C _asyncio module')

‎Lib/test/test_asyncio/test_runners.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ async def get_context():
402402

403403
self.assertEqual(2, runner.run(get_context()).get(cvar))
404404

405-
@unittest.expectedFailure # TODO: RUSTPYTHON; - RuntimeWarning for unawaited coroutine not triggered
406405
def test_recursive_run(self):
407406
async def g():
408407
pass

‎Lib/test/test_asyncio/test_streams.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,6 @@ async def handle_echo(reader, writer):
12391239
messages = self._basetest_unhandled_exceptions(handle_echo)
12401240
self.assertEqual(messages, [])
12411241

1242-
@unittest.expectedFailure # TODO: RUSTPYTHON; NotImplementedError
12431242
def test_open_connection_happy_eyeball_refcycles(self):
12441243
port = socket_helper.find_unused_port()
12451244
async def main():

‎Lib/test/test_asyncio/test_taskgroups.py‎

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,29 +1106,6 @@ async def throw_error():
11061106
class TestTaskGroup(BaseTestTaskGroup, unittest.IsolatedAsyncioTestCase):
11071107
loop_factory = asyncio.EventLoop
11081108

1109-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes propagate_cancellation_error
1110-
async def test_exception_refcycles_propagate_cancellation_error(self):
1111-
return await super().test_exception_refcycles_propagate_cancellation_error()
1112-
1113-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes self._base_error
1114-
async def test_exception_refcycles_base_error(self):
1115-
return await super().test_exception_refcycles_base_error()
1116-
1117-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes self._errors, and __aexit__ args
1118-
async def test_exception_refcycles_errors(self):
1119-
return await super().test_exception_refcycles_errors()
1120-
1121-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes self._parent_task
1122-
async def test_exception_refcycles_parent_task(self):
1123-
return await super().test_exception_refcycles_parent_task()
1124-
1125-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes self._parent_task and create_task() deletes task
1126-
async def test_exception_refcycles_parent_task_wr(self):
1127-
return await super().test_exception_refcycles_parent_task_wr()
1128-
1129-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup doesn't keep a reference to the raised ExceptionGroup
1130-
async def test_exception_refcycles_direct(self):
1131-
return await super().test_exception_refcycles_direct()
11321109

11331110
class TestEagerTaskTaskGroup(BaseTestTaskGroup, unittest.IsolatedAsyncioTestCase):
11341111
@staticmethod
@@ -1137,30 +1114,6 @@ def loop_factory():
11371114
loop.set_task_factory(asyncio.eager_task_factory)
11381115
return loop
11391116

1140-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes propagate_cancellation_error
1141-
async def test_exception_refcycles_propagate_cancellation_error(self):
1142-
return await super().test_exception_refcycles_propagate_cancellation_error()
1143-
1144-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes self._base_error
1145-
async def test_exception_refcycles_base_error(self):
1146-
return await super().test_exception_refcycles_base_error()
1147-
1148-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes self._errors, and __aexit__ args
1149-
async def test_exception_refcycles_errors(self):
1150-
return await super().test_exception_refcycles_errors()
1151-
1152-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes self._parent_task
1153-
async def test_exception_refcycles_parent_task(self):
1154-
return await super().test_exception_refcycles_parent_task()
1155-
1156-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup deletes self._parent_task and create_task() deletes task
1157-
async def test_exception_refcycles_parent_task_wr(self):
1158-
return await super().test_exception_refcycles_parent_task_wr()
1159-
1160-
@unittest.expectedFailure # TODO: RUSTPYTHON; Test that TaskGroup doesn't keep a reference to the raised ExceptionGroup
1161-
async def test_exception_refcycles_direct(self):
1162-
return await super().test_exception_refcycles_direct()
1163-
11641117

11651118
if __name__ == "__main__":
11661119
unittest.main()

‎Lib/test/test_asyncio/test_tasks.py‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,10 +2942,6 @@ async def coro():
29422942
with self.assertRaises(AttributeError):
29432943
del task._log_destroy_pending
29442944

2945-
@unittest.expectedFailure # TODO: RUSTPYTHON; Actual: not called.
2946-
def test_log_destroyed_pending_task(self):
2947-
return super().test_log_destroyed_pending_task()
2948-
29492945

29502946
@unittest.skipUnless(hasattr(futures, '_CFuture') and
29512947
hasattr(tasks, '_CTask'),
@@ -2958,10 +2954,6 @@ class CTask_CFuture_SubclassTests(BaseTaskTests, test_utils.TestCase):
29582954
all_tasks = getattr(tasks, '_c_all_tasks', None)
29592955
current_task = staticmethod(getattr(tasks, '_c_current_task', None))
29602956

2961-
@unittest.expectedFailure # TODO: RUSTPYTHON; Actual: not called.
2962-
def test_log_destroyed_pending_task(self):
2963-
return super().test_log_destroyed_pending_task()
2964-
29652957

29662958
@unittest.skipUnless(hasattr(tasks, '_CTask'),
29672959
'requires the C _asyncio module')
@@ -2973,10 +2965,6 @@ class CTaskSubclass_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
29732965
all_tasks = getattr(tasks, '_c_all_tasks', None)
29742966
current_task = staticmethod(getattr(tasks, '_c_current_task', None))
29752967

2976-
@unittest.expectedFailure # TODO: RUSTPYTHON; Actual: not called.
2977-
def test_log_destroyed_pending_task(self):
2978-
return super().test_log_destroyed_pending_task()
2979-
29802968

29812969
@unittest.skipUnless(hasattr(futures, '_CFuture'),
29822970
'requires the C _asyncio module')
@@ -2998,10 +2986,6 @@ class CTask_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
29982986
all_tasks = getattr(tasks, '_c_all_tasks', None)
29992987
current_task = staticmethod(getattr(tasks, '_c_current_task', None))
30002988

3001-
@unittest.expectedFailure # TODO: RUSTPYTHON; Actual: not called.
3002-
def test_log_destroyed_pending_task(self):
3003-
return super().test_log_destroyed_pending_task()
3004-
30052989

30062990
@unittest.skipUnless(hasattr(futures, '_CFuture'),
30072991
'requires the C _asyncio module')

‎Lib/test/test_coroutines.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,6 @@ async def run_gen():
22302230
return 'end'
22312231
self.assertEqual(run_async(run_gen()), ([], 'end'))
22322232

2233-
@unittest.expectedFailure # TODO: RUSTPYTHON; This would crash the interpreter in 3.11a2
22342233
def test_bpo_45813_1(self):
22352234
'This would crash the interpreter in 3.11a2'
22362235
async def f():

‎Lib/test/test_unittest/testmock/testasync.py‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ def test_spec_async_attributes_instance(self):
336336
# only the shape of the spec at the time of mock construction matters
337337
self.assertNotIsInstance(mock_async_instance.later_async_func_attr, AsyncMock)
338338

339-
@unittest.expectedFailure # TODO: RUSTPYTHON
340339
def test_spec_mock_type_kw(self):
341340
def inner_test(mock_type):
342341
async_mock = mock_type(spec=async_func)
@@ -351,7 +350,6 @@ def inner_test(mock_type):
351350
with self.subTest(f"test spec kwarg with {mock_type}"):
352351
inner_test(mock_type)
353352

354-
@unittest.expectedFailure # TODO: RUSTPYTHON
355353
def test_spec_mock_type_positional(self):
356354
def inner_test(mock_type):
357355
async_mock = mock_type(async_func)
@@ -800,7 +798,6 @@ async def _runnable_test(self, *args, **kwargs):
800798
async def _await_coroutine(self, coroutine):
801799
return await coroutine
802800

803-
@unittest.expectedFailure # TODO: RUSTPYTHON
804801
def test_assert_called_but_not_awaited(self):
805802
mock = AsyncMock(AsyncClass)
806803
with assertNeverAwaited(self):
@@ -841,7 +838,6 @@ def test_assert_called_and_awaited_at_same_time(self):
841838
self.mock.assert_called_once()
842839
self.mock.assert_awaited_once()
843840

844-
@unittest.expectedFailure # TODO: RUSTPYTHON
845841
def test_assert_called_twice_and_awaited_once(self):
846842
mock = AsyncMock(AsyncClass)
847843
coroutine = mock.async_method()
@@ -881,7 +877,6 @@ def test_assert_awaited_but_not_called(self):
881877
with self.assertRaises(AssertionError):
882878
self.mock.assert_called()
883879

884-
@unittest.expectedFailure # TODO: RUSTPYTHON
885880
def test_assert_has_calls_not_awaits(self):
886881
kalls = [call('foo')]
887882
with assertNeverAwaited(self):
@@ -890,7 +885,6 @@ def test_assert_has_calls_not_awaits(self):
890885
with self.assertRaises(AssertionError):
891886
self.mock.assert_has_awaits(kalls)
892887

893-
@unittest.expectedFailure # TODO: RUSTPYTHON
894888
def test_assert_has_mock_calls_on_async_mock_no_spec(self):
895889
with assertNeverAwaited(self):
896890
self.mock()
@@ -904,7 +898,6 @@ def test_assert_has_mock_calls_on_async_mock_no_spec(self):
904898
mock_kalls = ([call(), call('foo'), call('baz')])
905899
self.assertEqual(self.mock.mock_calls, mock_kalls)
906900

907-
@unittest.expectedFailure # TODO: RUSTPYTHON
908901
def test_assert_has_mock_calls_on_async_mock_with_spec(self):
909902
a_class_mock = AsyncMock(AsyncClass)
910903
with assertNeverAwaited(self):
@@ -920,7 +913,6 @@ def test_assert_has_mock_calls_on_async_mock_with_spec(self):
920913
self.assertEqual(a_class_mock.async_method.mock_calls, method_kalls)
921914
self.assertEqual(a_class_mock.mock_calls, mock_kalls)
922915

923-
@unittest.expectedFailure # TODO: RUSTPYTHON
924916
def test_async_method_calls_recorded(self):
925917
with assertNeverAwaited(self):
926918
self.mock.something(3, fish=None)
@@ -936,7 +928,6 @@ def test_async_method_calls_recorded(self):
936928
[("something", (6,), {'cake': sentinel.Cake})],
937929
"method calls not recorded correctly")
938930

939-
@unittest.expectedFailure # TODO: RUSTPYTHON
940931
def test_async_arg_lists(self):
941932
def assert_attrs(mock):
942933
names = ('call_args_list', 'method_calls', 'mock_calls')

‎crates/stdlib/src/_asyncio.rs‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,15 +1876,11 @@ pub(crate) mod _asyncio {
18761876
{
18771877
if let Some(loop_obj) = loop_obj.clone() {
18781878
let context = PyDict::default().into_ref(&vm.ctx);
1879-
let task_repr = zelf
1880-
.as_object()
1881-
.repr(vm)
1882-
.unwrap_or_else(|_| vm.ctx.new_str("<Task>"));
1883-
let message =
1884-
format!("Task was destroyed but it is pending!\ntask: {task_repr}");
18851879
context.set_item(
18861880
vm.ctx.intern_str("message"),
1887-
vm.ctx.new_str(message).into(),
1881+
vm.ctx
1882+
.new_str("Task was destroyed but it is pending!")
1883+
.into(),
18881884
vm,
18891885
)?;
18901886
context.set_item(vm.ctx.intern_str("task"), zelf.to_owned().into(), vm)?;

‎crates/vm/src/builtins/coroutine.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ impl Destructor for PyCoroutine {
163163
return Ok(());
164164
}
165165
if zelf.inner.frame().lasti() == 0 {
166+
let name = zelf.inner.qualname();
167+
let msg = format!("coroutine '{name}' was never awaited");
168+
if let Err(e) =
169+
crate::stdlib::_warnings::warn(vm.ctx.exceptions.runtime_warning, msg, 1, vm)
170+
{
171+
vm.run_unraisable(e, None, zelf.as_object().to_owned());
172+
}
166173
zelf.inner.closed.store(true);
167174
return Ok(());
168175
}

0 commit comments

Comments
 (0)