@@ -31,7 +31,7 @@ use futures::{channel::mpsc, SinkExt};
3131use once_cell:: sync:: OnceCell ;
3232use pin_project_lite:: pin_project;
3333use pyo3:: prelude:: * ;
34- use pyo3:: BoundObject ;
34+ use pyo3:: { BoundObject , IntoPyObjectExt } ;
3535#[ cfg( feature = "unstable-streams" ) ]
3636use std:: marker:: PhantomData ;
3737
@@ -349,10 +349,7 @@ fn set_result(
349349
350350 let ( complete, val) = match result {
351351 Ok ( val) => ( future. getattr ( "set_result" ) ?, val. into_pyobject ( py) ?) ,
352- Err ( err) => (
353- future. getattr ( "set_exception" ) ?,
354- err. into_pyobject ( py) ?. into_any ( ) ,
355- ) ,
352+ Err ( err) => ( future. getattr ( "set_exception" ) ?, err. into_bound_py_any ( py) ?) ,
356353 } ;
357354 call_soon_threadsafe ( event_loop, & none, ( CheckedCompletor , future, complete, val) ) ?;
358355
@@ -457,7 +454,7 @@ fn set_result(
457454/// Python::attach(|py| {
458455/// pyo3_async_runtimes::generic::into_future::<MyCustomRuntime>(
459456/// test_mod
460- /// .call_method1(py, "py_sleep", (seconds.into_pyobject(py).unwrap() ,))?
457+ /// .call_method1(py, "py_sleep", (seconds,))?
461458/// .into_bound(py),
462459/// )
463460/// })?
@@ -622,10 +619,7 @@ where
622619 let _ = set_result (
623620 & locals2. event_loop ( py) ,
624621 future_tx1. bind ( py) ,
625- result. and_then ( |val| match val. into_pyobject ( py) {
626- Ok ( obj) => Ok ( obj. into_any ( ) . unbind ( ) ) ,
627- Err ( err) => Err ( err. into ( ) ) ,
628- } ) ,
622+ result. and_then ( |val| val. into_py_any ( py) ) ,
629623 )
630624 . map_err ( dump_err ( py) ) ;
631625 } ) ;
@@ -1030,10 +1024,7 @@ where
10301024 let _ = set_result (
10311025 locals2. event_loop . bind ( py) ,
10321026 future_tx1. bind ( py) ,
1033- result. and_then ( |val| match val. into_pyobject ( py) {
1034- Ok ( obj) => Ok ( obj. into_any ( ) . unbind ( ) ) ,
1035- Err ( err) => Err ( err. into ( ) ) ,
1036- } ) ,
1027+ result. and_then ( |val| val. into_py_any ( py) ) ,
10371028 )
10381029 . map_err ( dump_err ( py) ) ;
10391030 } ) ;
@@ -1480,7 +1471,7 @@ where
14801471{
14811472 fn send ( & mut self , py : Python , locals : TaskLocals , item : Py < PyAny > ) -> PyResult < Py < PyAny > > {
14821473 match self . tx . try_send ( item. clone_ref ( py) ) {
1483- Ok ( _) => Ok ( true . into_pyobject ( py) ? . into_any ( ) . unbind ( ) ) ,
1474+ Ok ( _) => true . into_py_any ( py) ,
14841475 Err ( e) => {
14851476 if e. is_full ( ) {
14861477 let mut tx = self . tx . clone ( ) ;
@@ -1492,26 +1483,20 @@ where
14921483 async move {
14931484 if tx. flush ( ) . await . is_err ( ) {
14941485 // receiving side disconnected
1495- return Python :: attach ( |py| {
1496- Ok ( false . into_pyobject ( py) ?. into_any ( ) . unbind ( ) )
1497- } ) ;
1486+ return Python :: attach ( |py| false . into_py_any ( py) ) ;
14981487 }
14991488 if tx. send ( item) . await . is_err ( ) {
15001489 // receiving side disconnected
1501- return Python :: attach ( |py| {
1502- Ok ( false . into_pyobject ( py) ?. into_any ( ) . unbind ( ) )
1503- } ) ;
1490+ return Python :: attach ( |py| false . into_py_any ( py) ) ;
15041491 }
1505- Python :: attach ( |py| {
1506- Ok ( true . into_pyobject ( py) ?. into_any ( ) . unbind ( ) )
1507- } )
1492+ Python :: attach ( |py| true . into_py_any ( py) )
15081493 } ,
15091494 ) ?
15101495 . into ( ) ,
15111496 )
15121497 } )
15131498 } else {
1514- Ok ( false . into_pyobject ( py) ? . into_any ( ) . unbind ( ) )
1499+ false . into_py_any ( py)
15151500 }
15161501 }
15171502 }
0 commit comments