@@ -2473,7 +2473,7 @@ mod _io {
24732473 vm. call_method ( & textio. buffer , "flush" , ( ) )
24742474 }
24752475
2476- #[ pyclass( with( Constructor , Initializer , Destructor ) , flags( BASETYPE ) ) ]
2476+ #[ pyclass( with( Constructor , Initializer , Destructor , Iterable , IterNext ) , flags( BASETYPE ) ) ]
24772477 impl TextIOWrapper {
24782478 #[ pymethod]
24792479 fn reconfigure ( & self , args : TextIOWrapperArgs , vm : & VirtualMachine ) -> PyResult < ( ) > {
@@ -3348,6 +3348,44 @@ mod _io {
33483348 }
33493349 }
33503350
3351+ impl Iterable for TextIOWrapper {
3352+ fn slot_iter ( zelf : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
3353+ check_closed ( & zelf, vm) ?;
3354+ Ok ( zelf)
3355+ }
3356+
3357+ fn iter ( _zelf : PyRef < Self > , _vm : & VirtualMachine ) -> PyResult {
3358+ unreachable ! ( "slot_iter is implemented" )
3359+ }
3360+ }
3361+
3362+ impl IterNext for TextIOWrapper {
3363+ fn slot_iternext ( zelf : & PyObject , vm : & VirtualMachine ) -> PyResult < PyIterReturn > {
3364+ // Set telling = false during iteration (matches CPython behavior)
3365+ let textio_ref: PyRef < TextIOWrapper > = zelf. downcast_ref :: < TextIOWrapper > ( ) . unwrap ( ) . to_owned ( ) ;
3366+ {
3367+ let mut textio = textio_ref. lock ( vm) ?;
3368+ textio. telling = false ;
3369+ }
3370+
3371+ let line = vm. call_method ( zelf, "readline" , ( ) ) ?;
3372+
3373+ if !line. clone ( ) . try_to_bool ( vm) ? {
3374+ // Restore telling on StopIteration
3375+ let mut textio = textio_ref. lock ( vm) ?;
3376+ textio. snapshot = None ;
3377+ textio. telling = textio. seekable ;
3378+ Ok ( PyIterReturn :: StopIteration ( None ) )
3379+ } else {
3380+ Ok ( PyIterReturn :: Return ( line) )
3381+ }
3382+ }
3383+
3384+ fn next ( _zelf : & Py < Self > , _vm : & VirtualMachine ) -> PyResult < PyIterReturn > {
3385+ unreachable ! ( "slot_iternext is implemented" )
3386+ }
3387+ }
3388+
33513389 #[ pyattr]
33523390 #[ pyclass( name) ]
33533391 #[ derive( Debug , PyPayload , Default ) ]
0 commit comments