11mod common;
22
3+ use std:: ffi:: CString ;
34use std:: {
45 rc:: Rc ,
56 sync:: { Arc , Mutex } ,
@@ -30,15 +31,15 @@ fn sleep<'p>(py: Python<'p>, secs: Bound<'p, PyAny>) -> PyResult<Bound<'p, PyAny
3031#[ pyo3_async_runtimes:: async_std:: test]
3132async fn test_future_into_py ( ) -> PyResult < ( ) > {
3233 let fut = Python :: with_gil ( |py| {
33- let sleeper_mod = PyModule :: new_bound ( py, "rust_sleeper" ) ?;
34+ let sleeper_mod = PyModule :: new ( py, "rust_sleeper" ) ?;
3435
3536 sleeper_mod. add_wrapped ( wrap_pyfunction ! ( sleep) ) ?;
3637
37- let test_mod = PyModule :: from_code_bound (
38+ let test_mod = PyModule :: from_code (
3839 py,
39- common:: TEST_MOD ,
40- "test_future_into_py_mod.py" ,
41- "test_future_into_py_mod" ,
40+ & CString :: new ( common:: TEST_MOD ) . unwrap ( ) ,
41+ & CString :: new ( "test_future_into_py_mod.py" ) . unwrap ( ) ,
42+ & CString :: new ( "test_future_into_py_mod" ) . unwrap ( ) ,
4243 ) ?;
4344
4445 pyo3_async_runtimes:: async_std:: into_future (
@@ -53,10 +54,7 @@ async fn test_future_into_py() -> PyResult<()> {
5354
5455#[ pyo3_async_runtimes:: async_std:: test]
5556async fn test_async_sleep ( ) -> PyResult < ( ) > {
56- let asyncio = Python :: with_gil ( |py| {
57- py. import_bound ( "asyncio" )
58- . map ( |asyncio| PyObject :: from ( asyncio) )
59- } ) ?;
57+ let asyncio = Python :: with_gil ( |py| py. import ( "asyncio" ) . map ( PyObject :: from) ) ?;
6058
6159 task:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
6260
@@ -157,8 +155,8 @@ async fn test_cancel() -> PyResult<()> {
157155 . await
158156 {
159157 Python :: with_gil ( |py| -> PyResult < ( ) > {
160- assert ! ( e. value_bound ( py) . is_instance(
161- py. import_bound ( "asyncio" ) ?
158+ assert ! ( e. value ( py) . is_instance(
159+ py. import ( "asyncio" ) ?
162160 . getattr( "CancelledError" ) ?
163161 . downcast:: <PyType >( )
164162 . unwrap( )
@@ -191,18 +189,18 @@ async def gen():
191189#[ pyo3_async_runtimes:: async_std:: test]
192190async fn test_async_gen_v1 ( ) -> PyResult < ( ) > {
193191 let stream = Python :: with_gil ( |py| {
194- let test_mod = PyModule :: from_code_bound (
192+ let test_mod = PyModule :: from_code (
195193 py,
196- ASYNC_STD_TEST_MOD ,
197- "test_rust_coroutine/async_std_test_mod.py" ,
198- "async_std_test_mod" ,
194+ & CString :: new ( ASYNC_STD_TEST_MOD ) . unwrap ( ) ,
195+ & CString :: new ( "test_rust_coroutine/async_std_test_mod.py" ) . unwrap ( ) ,
196+ & CString :: new ( "async_std_test_mod" ) . unwrap ( ) ,
199197 ) ?;
200198
201199 pyo3_async_runtimes:: async_std:: into_stream_v1 ( test_mod. call_method0 ( "gen" ) ?)
202200 } ) ?;
203201
204202 let vals = stream
205- . map ( |item| Python :: with_gil ( |py| -> PyResult < i32 > { Ok ( item?. bind ( py) . extract ( ) ? ) } ) )
203+ . map ( |item| Python :: with_gil ( |py| -> PyResult < i32 > { item?. bind ( py) . extract ( ) } ) )
206204 . try_collect :: < Vec < i32 > > ( )
207205 . await ?;
208206
@@ -214,7 +212,7 @@ async fn test_async_gen_v1() -> PyResult<()> {
214212#[ pyo3_async_runtimes:: async_std:: test]
215213fn test_local_cancel ( event_loop : PyObject ) -> PyResult < ( ) > {
216214 let locals = Python :: with_gil ( |py| -> PyResult < TaskLocals > {
217- Ok ( TaskLocals :: new ( event_loop. into_bound ( py) ) . copy_context ( py) ? )
215+ TaskLocals :: new ( event_loop. into_bound ( py) ) . copy_context ( py)
218216 } ) ?;
219217 async_std:: task:: block_on ( pyo3_async_runtimes:: async_std:: scope_local ( locals, async {
220218 let completed = Arc :: new ( Mutex :: new ( false ) ) ;
@@ -239,8 +237,8 @@ fn test_local_cancel(event_loop: PyObject) -> PyResult<()> {
239237 . await
240238 {
241239 Python :: with_gil ( |py| -> PyResult < ( ) > {
242- assert ! ( e. value_bound ( py) . is_instance(
243- py. import_bound ( "asyncio" ) ?
240+ assert ! ( e. value ( py) . is_instance(
241+ py. import ( "asyncio" ) ?
244242 . getattr( "CancelledError" ) ?
245243 . downcast:: <PyType >( )
246244 . unwrap( )
@@ -297,13 +295,13 @@ fn test_multiple_asyncio_run() -> PyResult<()> {
297295 } ) ?;
298296
299297 let d = [
300- ( "asyncio" , py. import_bound ( "asyncio" ) ?. into ( ) ) ,
298+ ( "asyncio" , py. import ( "asyncio" ) ?. into ( ) ) ,
301299 ( "test_mod" , wrap_pymodule ! ( test_mod) ( py) ) ,
302300 ]
303- . into_py_dict_bound ( py) ;
301+ . into_py_dict ( py) ? ;
304302
305- py. run_bound ( MULTI_ASYNCIO_CODE , Some ( & d) , None ) ?;
306- py. run_bound ( MULTI_ASYNCIO_CODE , Some ( & d) , None ) ?;
303+ py. run ( & CString :: new ( MULTI_ASYNCIO_CODE ) . unwrap ( ) , Some ( & d) , None ) ?;
304+ py. run ( & CString :: new ( MULTI_ASYNCIO_CODE ) . unwrap ( ) , Some ( & d) , None ) ?;
307305 Ok ( ( ) )
308306 } )
309307}
@@ -332,18 +330,18 @@ fn cvars_mod(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
332330#[ pyo3_async_runtimes:: async_std:: test]
333331async fn test_async_gen_v2 ( ) -> PyResult < ( ) > {
334332 let stream = Python :: with_gil ( |py| {
335- let test_mod = PyModule :: from_code_bound (
333+ let test_mod = PyModule :: from_code (
336334 py,
337- ASYNC_STD_TEST_MOD ,
338- "test_rust_coroutine/async_std_test_mod.py" ,
339- "async_std_test_mod" ,
335+ & CString :: new ( ASYNC_STD_TEST_MOD ) . unwrap ( ) ,
336+ & CString :: new ( "test_rust_coroutine/async_std_test_mod.py" ) . unwrap ( ) ,
337+ & CString :: new ( "async_std_test_mod" ) . unwrap ( ) ,
340338 ) ?;
341339
342340 pyo3_async_runtimes:: async_std:: into_stream_v2 ( test_mod. call_method0 ( "gen" ) ?)
343341 } ) ?;
344342
345343 let vals = stream
346- . map ( |item| Python :: with_gil ( |py| -> PyResult < i32 > { Ok ( item. bind ( py) . extract ( ) ? ) } ) )
344+ . map ( |item| Python :: with_gil ( |py| -> PyResult < i32 > { item. bind ( py) . extract ( ) } ) )
347345 . try_collect :: < Vec < i32 > > ( )
348346 . await ?;
349347
@@ -369,14 +367,14 @@ asyncio.run(main())
369367fn test_contextvars ( ) -> PyResult < ( ) > {
370368 Python :: with_gil ( |py| {
371369 let d = [
372- ( "asyncio" , py. import_bound ( "asyncio" ) ?. into ( ) ) ,
373- ( "contextvars" , py. import_bound ( "contextvars" ) ?. into ( ) ) ,
370+ ( "asyncio" , py. import ( "asyncio" ) ?. into ( ) ) ,
371+ ( "contextvars" , py. import ( "contextvars" ) ?. into ( ) ) ,
374372 ( "cvars_mod" , wrap_pymodule ! ( cvars_mod) ( py) ) ,
375373 ]
376- . into_py_dict_bound ( py) ;
374+ . into_py_dict ( py) ? ;
377375
378- py. run_bound ( CONTEXTVARS_CODE , Some ( & d) , None ) ?;
379- py. run_bound ( CONTEXTVARS_CODE , Some ( & d) , None ) ?;
376+ py. run ( & CString :: new ( CONTEXTVARS_CODE ) . unwrap ( ) , Some ( & d) , None ) ?;
377+ py. run ( & CString :: new ( CONTEXTVARS_CODE ) . unwrap ( ) , Some ( & d) , None ) ?;
380378 Ok ( ( ) )
381379 } )
382380}
0 commit comments