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