@@ -204,13 +204,6 @@ impl PyErrStateNormalized {
204204 unsafe { ffi:: PyException_SetTraceback ( self . pvalue . as_ptr ( ) , tb) } ;
205205 }
206206
207- #[ cfg_attr( not( Py_3_12 ) , allow( unused) ) ]
208- pub ( crate ) fn set_context ( & self , _py : Python < ' _ > , context : Option < Bound < ' _ , PyBaseException > > ) {
209- let context = context. map ( Bound :: into_ptr) . unwrap_or ( std:: ptr:: null_mut ( ) ) ;
210-
211- unsafe { ffi:: PyException_SetContext ( self . pvalue . as_ptr ( ) , context) } ;
212- }
213-
214207 pub ( crate ) fn take ( py : Python < ' _ > ) -> Option < PyErrStateNormalized > {
215208 #[ cfg( Py_3_12 ) ]
216209 {
@@ -410,7 +403,7 @@ fn raise_lazy(py: Python<'_>, lazy: Box<PyErrStateLazyFn>) {
410403 {
411404 let exc = create_normalized_exception ( ptype. bind ( py) , pvalue. into_bound ( py) ) ;
412405
413- ffi:: PyErr_SetRaisedException ( exc. pvalue . into_ptr ( ) ) ;
406+ ffi:: PyErr_SetRaisedException ( exc. into_ptr ( ) ) ;
414407 }
415408 }
416409}
@@ -419,7 +412,7 @@ fn raise_lazy(py: Python<'_>, lazy: Box<PyErrStateLazyFn>) {
419412fn create_normalized_exception < ' py > (
420413 ptype : & Bound < ' py , PyAny > ,
421414 mut pvalue : Bound < ' py , PyAny > ,
422- ) -> PyErrStateNormalized {
415+ ) -> Bound < ' py , PyBaseException > {
423416 let py = ptype. py ( ) ;
424417
425418 // 1: check type is a subclass of BaseException
@@ -449,25 +442,12 @@ fn create_normalized_exception<'py>(
449442
450443 match pvalue {
451444 Ok ( pvalue) => {
452- let normalized = PyErrStateNormalized {
453- #[ cfg( not( Py_3_12 ) ) ]
454- ptype,
455- pvalue : pvalue. unbind ( ) ,
456- #[ cfg( not( Py_3_12 ) ) ]
457- ptraceback : None ,
445+ unsafe {
446+ ffi:: PyException_SetContext ( pvalue. as_ptr ( ) , ffi:: PyErr_GetHandledException ( ) )
458447 } ;
459-
460- let context = unsafe {
461- ffi:: PyErr_GetHandledException ( )
462- . assume_owned_or_opt ( py)
463- . map ( |err| err. cast_into_unchecked ( ) )
464- } ;
465-
466- normalized. set_context ( py, context) ;
467-
468- normalized
448+ pvalue
469449 }
470- Err ( e) => e. normalized ( py) . clone_ref ( py ) ,
450+ Err ( e) => e. value ( py) . clone ( ) ,
471451 }
472452}
473453
0 commit comments