File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -1761,8 +1761,6 @@ def test_tee_del_backward(self):
1761
1761
del forward , backward
1762
1762
raise
1763
1763
1764
- # TODO: RUSTPYTHON
1765
- @unittest .expectedFailure
1766
1764
def test_tee_reenter (self ):
1767
1765
class I :
1768
1766
first = True
Original file line number Diff line number Diff line change @@ -1184,23 +1184,28 @@ mod decl {
1184
1184
#[ derive( Debug ) ]
1185
1185
struct PyItertoolsTeeData {
1186
1186
iterable : PyIter ,
1187
- values : PyRwLock < Vec < PyObjectRef > > ,
1187
+ values : PyMutex < Vec < PyObjectRef > > ,
1188
1188
}
1189
1189
1190
1190
impl PyItertoolsTeeData {
1191
1191
fn new ( iterable : PyIter , _vm : & VirtualMachine ) -> PyResult < PyRc < Self > > {
1192
1192
Ok ( PyRc :: new ( Self {
1193
1193
iterable,
1194
- values : PyRwLock :: new ( vec ! [ ] ) ,
1194
+ values : PyMutex :: new ( vec ! [ ] ) ,
1195
1195
} ) )
1196
1196
}
1197
1197
1198
1198
fn get_item ( & self , vm : & VirtualMachine , index : usize ) -> PyResult < PyIterReturn > {
1199
- if self . values . read ( ) . len ( ) == index {
1200
- let result = raise_if_stop ! ( self . iterable. next( vm) ?) ;
1201
- self . values . write ( ) . push ( result) ;
1199
+ let Some ( mut values) = self . values . try_lock ( ) else {
1200
+ return Err ( vm. new_runtime_error ( "cannot re-enter the tee iterator" ) ) ;
1201
+ } ;
1202
+
1203
+ if values. len ( ) == index {
1204
+ let obj = raise_if_stop ! ( self . iterable. next( vm) ?) ;
1205
+ values. push ( obj) ;
1202
1206
}
1203
- Ok ( PyIterReturn :: Return ( self . values . read ( ) [ index] . clone ( ) ) )
1207
+
1208
+ Ok ( PyIterReturn :: Return ( values[ index] . clone ( ) ) )
1204
1209
}
1205
1210
}
1206
1211
You can’t perform that action at this time.
0 commit comments