@@ -995,11 +995,33 @@ impl ExecutingFrame<'_> {
995
995
}
996
996
bytecode:: Instruction :: GetANext => {
997
997
let aiter = self . last_value ( ) ;
998
- let awaitable = vm. call_special_method ( & aiter, identifier ! ( vm, __anext__) , ( ) ) ?;
999
- let awaitable = if awaitable. payload_is :: < PyCoroutine > ( ) {
1000
- awaitable
998
+ let awaitable = if aiter. class ( ) . is ( vm. ctx . types . async_generator ) {
999
+ vm. call_special_method ( & aiter, identifier ! ( vm, __anext__) , ( ) ) ?
1001
1000
} else {
1002
- vm. call_special_method ( & awaitable, identifier ! ( vm, __await__) , ( ) ) ?
1001
+ assert ! ( false ) ;
1002
+ // if !hasattr(aiter, __anext__): raise TypeError("'async for' requires in iterator...")
1003
+ let next_iter =
1004
+ vm. call_special_method ( & aiter, identifier ! ( vm, __anext__) , ( ) ) ?;
1005
+
1006
+ // TODO: _PyCoro_GetAwaitableIter
1007
+ fn get_awaitable_iter ( next_iter : & PyObject , vm : & VirtualMachine ) -> PyResult {
1008
+ let gen_is_coroutine = |_| {
1009
+ // TODO:
1010
+ true
1011
+ } ;
1012
+ if next_iter. class ( ) . is ( vm. ctx . types . coroutine_type )
1013
+ || gen_is_coroutine ( next_iter)
1014
+ {
1015
+ return Ok ( next_iter. to_owned ( ) ) ;
1016
+ }
1017
+ vm. call_special_method ( next_iter, identifier ! ( vm, __await__) , ( ) )
1018
+ }
1019
+ get_awaitable_iter ( & next_iter, vm) . map_err ( |_| {
1020
+ vm. new_type_error ( format ! (
1021
+ "'async for' received an invalid object from __anext__: {:.200}" ,
1022
+ next_iter. class( ) . name( )
1023
+ ) )
1024
+ } ) ?
1003
1025
} ;
1004
1026
self . push_value ( awaitable) ;
1005
1027
Ok ( None )
0 commit comments