@@ -4,7 +4,7 @@ use crate::utils::*;
44use egglog:: ast:: Symbol ;
55use ordered_float:: OrderedFloat ;
66use pyo3:: prelude:: * ;
7- use pyo3:: types:: PyDeltaAccess ;
7+ use pyo3:: types:: { PyDelta , PyDeltaAccess } ;
88use std:: collections:: HashMap ;
99use std:: sync:: Arc ;
1010
@@ -460,9 +460,13 @@ impl FromPyObject<'_> for Box<Schedule> {
460460 }
461461}
462462
463- impl IntoPy < PyObject > for Box < Schedule > {
464- fn into_py ( self , py : Python < ' _ > ) -> PyObject {
465- ( * self ) . into_py ( py)
463+ impl < ' py > IntoPyObject < ' py > for Box < Schedule > {
464+ type Target = PyAny ; // the Python type
465+ type Output = Bound < ' py , Self :: Target > ; // in most cases this will be `Bound`
466+ type Error = pyo3:: PyErr ;
467+
468+ fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , Self :: Error > {
469+ Ok ( ( * self ) . into_pyobject ( py) ?. as_any ( ) . clone ( ) )
466470 }
467471}
468472
@@ -472,9 +476,13 @@ impl FromPyObject<'_> for Box<Command> {
472476 }
473477}
474478
475- impl IntoPy < PyObject > for Box < Command > {
476- fn into_py ( self , py : Python < ' _ > ) -> PyObject {
477- ( * self ) . into_py ( py)
479+ impl < ' py > IntoPyObject < ' py > for Box < Command > {
480+ type Target = PyAny ; // the Python type
481+ type Output = Bound < ' py , Self :: Target > ; // in most cases this will be `Bound`
482+ type Error = pyo3:: PyErr ;
483+
484+ fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , Self :: Error > {
485+ Ok ( ( * self ) . into_pyobject ( py) ?. as_any ( ) . clone ( ) )
478486 }
479487}
480488
@@ -495,9 +503,13 @@ impl FromPyObject<'_> for WrappedOrderedF64 {
495503 }
496504}
497505
498- impl IntoPy < PyObject > for WrappedOrderedF64 {
499- fn into_py ( self , py : Python < ' _ > ) -> PyObject {
500- self . 0 . into_inner ( ) . into_py ( py)
506+ impl < ' py > IntoPyObject < ' py > for WrappedOrderedF64 {
507+ type Target = PyAny ; // the Python type
508+ type Output = Bound < ' py , Self :: Target > ; // in most cases this will be `Bound`
509+ type Error = pyo3:: PyErr ;
510+
511+ fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , Self :: Error > {
512+ Ok ( ( self . 0 . into_inner ( ) ) . into_pyobject ( py) ?. as_any ( ) . clone ( ) )
501513 }
502514}
503515
@@ -522,20 +534,22 @@ impl FromPyObject<'_> for WrappedDuration {
522534 ) ) )
523535 }
524536}
537+ impl < ' py > IntoPyObject < ' py > for WrappedDuration {
538+ type Target = PyDelta ; // the Python type
539+ type Output = Bound < ' py , Self :: Target > ; // in most cases this will be `Bound`
540+ type Error = pyo3:: PyErr ;
525541
526- impl IntoPy < PyObject > for WrappedDuration {
527- fn into_py ( self , py : Python < ' _ > ) -> PyObject {
542+ fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , Self :: Error > {
528543 let d = self . 0 ;
529- pyo3:: types:: PyDelta :: new_bound (
544+ Ok ( pyo3:: types:: PyDelta :: new (
530545 py,
531546 0 ,
532547 0 ,
533548 d. as_millis ( )
534549 . try_into ( )
535550 . expect ( "Failed to convert miliseconds to int32 when converting duration" ) ,
536551 true ,
537- )
538- . expect ( "Failed to contruct timedelta" )
539- . into ( )
552+ ) ?
553+ . clone ( ) )
540554 }
541555}
0 commit comments