@@ -8,15 +8,14 @@ use pyo3::exceptions::{PyIOError, PyStopAsyncIteration, PyStopIteration};
88use pyo3:: prelude:: * ;
99use pyo3:: types:: PyString ;
1010use pyo3:: { intern, IntoPyObjectExt } ;
11- use pyo3_async_runtimes:: tokio:: future_into_py;
11+ use pyo3_async_runtimes:: tokio:: { future_into_py, get_runtime } ;
1212use pyo3_bytes:: PyBytes ;
1313use pyo3_object_store:: { PyObjectStore , PyObjectStoreError , PyObjectStoreResult } ;
1414use tokio:: io:: { AsyncBufReadExt , AsyncReadExt , AsyncSeekExt , AsyncWriteExt , Lines } ;
1515use tokio:: sync:: Mutex ;
1616
1717use crate :: attributes:: PyAttributes ;
1818use crate :: list:: PyObjectMeta ;
19- use crate :: runtime:: get_runtime;
2019use crate :: tags:: PyTagSet ;
2120
2221#[ pyfunction]
@@ -28,7 +27,7 @@ pub(crate) fn open_reader(
2827 buffer_size : usize ,
2928) -> PyObjectStoreResult < PyReadableFile > {
3029 let store = store. into_inner ( ) ;
31- let runtime = get_runtime ( py ) ? ;
30+ let runtime = get_runtime ( ) ;
3231 let ( reader, meta) =
3332 py. allow_threads ( || runtime. block_on ( create_reader ( store, path, buffer_size) ) ) ?;
3433 Ok ( PyReadableFile :: new ( reader, meta, false ) )
@@ -105,7 +104,7 @@ impl PyReadableFile {
105104 let out = future_into_py ( py, read ( reader, size) ) ?;
106105 Ok ( out. unbind ( ) )
107106 } else {
108- let runtime = get_runtime ( py ) ? ;
107+ let runtime = get_runtime ( ) ;
109108 let out = py. allow_threads ( || runtime. block_on ( read ( reader, size) ) ) ?;
110109 out. into_py_any ( py)
111110 }
@@ -121,7 +120,7 @@ impl PyReadableFile {
121120 let out = future_into_py ( py, readline ( reader) ) ?;
122121 Ok ( out. unbind ( ) )
123122 } else {
124- let runtime = get_runtime ( py ) ? ;
123+ let runtime = get_runtime ( ) ;
125124 let out = py. allow_threads ( || runtime. block_on ( readline ( reader) ) ) ?;
126125 out. into_py_any ( py)
127126 }
@@ -135,7 +134,7 @@ impl PyReadableFile {
135134 let out = future_into_py ( py, readlines ( reader, hint) ) ?;
136135 Ok ( out. unbind ( ) )
137136 } else {
138- let runtime = get_runtime ( py ) ? ;
137+ let runtime = get_runtime ( ) ;
139138 let out = py. allow_threads ( || runtime. block_on ( readlines ( reader, hint) ) ) ?;
140139 out. into_py_any ( py)
141140 }
@@ -163,7 +162,7 @@ impl PyReadableFile {
163162 let out = future_into_py ( py, seek ( reader, pos) ) ?;
164163 Ok ( out. unbind ( ) )
165164 } else {
166- let runtime = get_runtime ( py ) ? ;
165+ let runtime = get_runtime ( ) ;
167166 let out = py. allow_threads ( || runtime. block_on ( seek ( reader, pos) ) ) ?;
168167 out. into_py_any ( py)
169168 }
@@ -184,7 +183,7 @@ impl PyReadableFile {
184183 let out = future_into_py ( py, tell ( reader) ) ?;
185184 Ok ( out. unbind ( ) )
186185 } else {
187- let runtime = get_runtime ( py ) ? ;
186+ let runtime = get_runtime ( ) ;
188187 let out = py. allow_threads ( || runtime. block_on ( tell ( reader) ) ) ?;
189188 out. into_py_any ( py)
190189 }
@@ -267,7 +266,7 @@ impl PyLinesReader {
267266 }
268267
269268 fn __next__ < ' py > ( & ' py self , py : Python < ' py > ) -> PyResult < String > {
270- let runtime = get_runtime ( py ) ? ;
269+ let runtime = get_runtime ( ) ;
271270 let lines = self . 0 . clone ( ) ;
272271 py. allow_threads ( || runtime. block_on ( next_line ( lines, false ) ) )
273272 }
@@ -376,7 +375,7 @@ impl PyWritableFile {
376375 traceback : Option < PyObject > ,
377376 ) -> PyResult < ( ) > {
378377 let writer = self . writer . clone ( ) ;
379- let runtime = get_runtime ( py ) ? ;
378+ let runtime = get_runtime ( ) ;
380379 if exc_type. is_some ( ) {
381380 py. allow_threads ( || runtime. block_on ( abort_writer ( writer) ) ) ?;
382381 } else {
@@ -395,7 +394,7 @@ impl PyWritableFile {
395394 traceback : Option < PyObject > ,
396395 ) -> PyResult < Bound < ' py , PyAny > > {
397396 let writer = self . writer . clone ( ) ;
398- let runtime = get_runtime ( py ) ? ;
397+ let runtime = get_runtime ( ) ;
399398 if exc_type. is_some ( ) {
400399 future_into_py ( py, abort_writer ( writer) )
401400 } else {
@@ -409,7 +408,7 @@ impl PyWritableFile {
409408 let out = future_into_py ( py, close_writer ( writer) ) ?;
410409 Ok ( out. unbind ( ) )
411410 } else {
412- let runtime = get_runtime ( py ) ? ;
411+ let runtime = get_runtime ( ) ;
413412 py. allow_threads ( || runtime. block_on ( close_writer ( writer) ) ) ?;
414413 Ok ( py. None ( ) )
415414 }
@@ -436,7 +435,7 @@ impl PyWritableFile {
436435 let out = future_into_py ( py, is_closed ( writer) ) ?;
437436 Ok ( out. unbind ( ) )
438437 } else {
439- let runtime = get_runtime ( py ) ? ;
438+ let runtime = get_runtime ( ) ;
440439 let out = py. allow_threads ( || runtime. block_on ( is_closed ( writer) ) ) ?;
441440 out. into_py_any ( py)
442441 }
@@ -448,7 +447,7 @@ impl PyWritableFile {
448447 let out = future_into_py ( py, flush ( writer) ) ?;
449448 Ok ( out. unbind ( ) )
450449 } else {
451- let runtime = get_runtime ( py ) ? ;
450+ let runtime = get_runtime ( ) ;
452451 py. allow_threads ( || runtime. block_on ( flush ( writer) ) ) ?;
453452 Ok ( py. None ( ) )
454453 }
@@ -460,7 +459,7 @@ impl PyWritableFile {
460459 let out = future_into_py ( py, write ( writer, buffer) ) ?;
461460 Ok ( out. unbind ( ) )
462461 } else {
463- let runtime = get_runtime ( py ) ? ;
462+ let runtime = get_runtime ( ) ;
464463 let out = py. allow_threads ( || runtime. block_on ( write ( writer, buffer) ) ) ?;
465464 out. into_py_any ( py)
466465 }
0 commit comments