From d08b04e48e976290be8ef033186b60e97b97f917 Mon Sep 17 00:00:00 2001 From: Yash Suthar Date: Wed, 29 Oct 2025 02:42:13 +0530 Subject: [PATCH 1/3] Implement minimal builtins.anext() issue : #3609 Signed-off-by: Yash Suthar --- vm/src/stdlib/builtins.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vm/src/stdlib/builtins.rs b/vm/src/stdlib/builtins.rs index 8cf99770e7..dfc3e5a532 100644 --- a/vm/src/stdlib/builtins.rs +++ b/vm/src/stdlib/builtins.rs @@ -534,6 +534,22 @@ mod builtins { iter_target.get_aiter(vm) } + #[pyfunction] + fn anext( + aiter: PyObjectRef, + default_value: OptionalArg, + vm: &VirtualMachine, + ) -> PyResult { + let awaitable = vm.call_method(&aiter, "__anext__", ())?; + + if default_value.is_missing() { + Ok(awaitable) + } else { + // TODO: Implement CPython like PyAnextAwaitable to properly handle the default value. + Ok(awaitable) + } + } + #[pyfunction] fn len(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { obj.length(vm) From a39384548d77ed1bcf5d069408ae1b30ac1c861e Mon Sep 17 00:00:00 2001 From: Yash Suthar Date: Wed, 29 Oct 2025 13:17:05 +0530 Subject: [PATCH 2/3] Removed expectedFailure for builtins.anext() tests Signed-off-by: Yash Suthar --- Lib/test/test_asyncgen.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py index f97316adeb..797ce1c091 100644 --- a/Lib/test/test_asyncgen.py +++ b/Lib/test/test_asyncgen.py @@ -603,8 +603,6 @@ async def check_anext_returning_iterator(self, aiter_class): await awaitable return "completed" - # TODO: RUSTPYTHON, NameError: name 'anext' is not defined - @unittest.expectedFailure def test_anext_return_iterator(self): class WithIterAnext: def __aiter__(self): @@ -614,8 +612,6 @@ def __anext__(self): result = self.loop.run_until_complete(self.check_anext_returning_iterator(WithIterAnext)) self.assertEqual(result, "completed") - # TODO: RUSTPYTHON, NameError: name 'anext' is not defined - @unittest.expectedFailure def test_anext_return_generator(self): class WithGenAnext: def __aiter__(self): @@ -625,8 +621,6 @@ def __anext__(self): result = self.loop.run_until_complete(self.check_anext_returning_iterator(WithGenAnext)) self.assertEqual(result, "completed") - # TODO: RUSTPYTHON, NameError: name 'anext' is not defined - @unittest.expectedFailure def test_anext_await_raises(self): class RaisingAwaitable: def __await__(self): From 82aae89f05331b0172f3add609694eada62afbae Mon Sep 17 00:00:00 2001 From: Yash Suthar Date: Wed, 29 Oct 2025 14:26:57 +0530 Subject: [PATCH 3/3] Removed expectedFailure from test_contextlib_async tests fixed by anext Signed-off-by: Yash Suthar --- Lib/test/test_contextlib_async.py | 32 ------------------------------- 1 file changed, 32 deletions(-) diff --git a/Lib/test/test_contextlib_async.py b/Lib/test/test_contextlib_async.py index 5673c1b4bc..f7edcfe55d 100644 --- a/Lib/test/test_contextlib_async.py +++ b/Lib/test/test_contextlib_async.py @@ -40,8 +40,6 @@ async def __aexit__(self, *args): manager = DefaultAsyncContextManager() manager.var = 42 - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_async_gen_propagates_generator_exit(self): # A regression test for https://bugs.python.org/issue33786. @@ -94,8 +92,6 @@ class NoneAexit(ManagerFromScratch): class AsyncContextManagerTestCase(unittest.IsolatedAsyncioTestCase): - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_contextmanager_plain(self): state = [] @asynccontextmanager @@ -109,8 +105,6 @@ async def woohoo(): state.append(x) self.assertEqual(state, [1, 42, 999]) - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_contextmanager_finally(self): state = [] @asynccontextmanager @@ -185,8 +179,6 @@ class StopAsyncIterationSubclass(StopAsyncIteration): self.assertEqual(frames[0].name, 'test_contextmanager_traceback') self.assertEqual(frames[0].line, 'raise stop_exc') - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_contextmanager_no_reraise(self): @asynccontextmanager async def whee(): @@ -196,8 +188,6 @@ async def whee(): # Calling __aexit__ should not result in an exception self.assertFalse(await ctx.__aexit__(TypeError, TypeError("foo"), None)) - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_contextmanager_trap_yield_after_throw(self): @asynccontextmanager async def whoo(): @@ -213,8 +203,6 @@ async def whoo(): # The "gen" attribute is an implementation detail. self.assertFalse(ctx.gen.ag_suspended) - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_contextmanager_trap_no_yield(self): @asynccontextmanager async def whoo(): @@ -224,8 +212,6 @@ async def whoo(): with self.assertRaises(RuntimeError): await ctx.__aenter__() - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_contextmanager_trap_second_yield(self): @asynccontextmanager async def whoo(): @@ -239,8 +225,6 @@ async def whoo(): # The "gen" attribute is an implementation detail. self.assertFalse(ctx.gen.ag_suspended) - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_contextmanager_non_normalised(self): @asynccontextmanager async def whoo(): @@ -254,8 +238,6 @@ async def whoo(): with self.assertRaises(SyntaxError): await ctx.__aexit__(RuntimeError, None, None) - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_contextmanager_except(self): state = [] @asynccontextmanager @@ -301,8 +283,6 @@ class StopAsyncIterationSubclass(StopAsyncIteration): else: self.fail(f'{stop_exc} was suppressed') - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_contextmanager_wrap_runtimeerror(self): @asynccontextmanager async def woohoo(): @@ -346,8 +326,6 @@ def test_contextmanager_doc_attrib(self): baz = self._create_contextmanager_attribs() self.assertEqual(baz.__doc__, "Whee!") - # TODO: RUSTPYTHON - @unittest.expectedFailure @support.requires_docstrings async def test_instance_docstring_given_cm_docstring(self): baz = self._create_contextmanager_attribs()(None) @@ -355,8 +333,6 @@ async def test_instance_docstring_given_cm_docstring(self): async with baz: pass # suppress warning - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_keywords(self): # Ensure no keyword arguments are inhibited @asynccontextmanager @@ -365,8 +341,6 @@ async def woohoo(self, func, args, kwds): async with woohoo(self=11, func=22, args=33, kwds=44) as target: self.assertEqual(target, (11, 22, 33, 44)) - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_recursive(self): depth = 0 ncols = 0 @@ -393,8 +367,6 @@ async def recursive(): self.assertEqual(ncols, 10) self.assertEqual(depth, 0) - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_decorator(self): entered = False @@ -413,8 +385,6 @@ async def test(): await test() self.assertFalse(entered) - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_decorator_with_exception(self): entered = False @@ -437,8 +407,6 @@ async def test(): await test() self.assertFalse(entered) - # TODO: RUSTPYTHON - @unittest.expectedFailure async def test_decorating_method(self): @asynccontextmanager