@@ -3,11 +3,13 @@ use crate::panic::PanicException;
33use crate :: type_object:: PyTypeInfo ;
44use crate :: types:: any:: PyAnyMethods ;
55use crate :: types:: { string:: PyStringMethods , typeobject:: PyTypeMethods , PyTraceback , PyType } ;
6+ #[ cfg( feature = "gil-refs" ) ]
7+ use crate :: PyNativeType ;
68use crate :: {
79 exceptions:: { self , PyBaseException } ,
810 ffi,
911} ;
10- use crate :: { Borrowed , IntoPy , Py , PyAny , PyNativeType , PyObject , Python , ToPyObject } ;
12+ use crate :: { Borrowed , IntoPy , Py , PyAny , PyObject , Python , ToPyObject } ;
1113use std:: borrow:: Cow ;
1214use std:: cell:: UnsafeCell ;
1315use std:: ffi:: CString ;
@@ -47,11 +49,13 @@ pub type PyResult<T> = Result<T, PyErr>;
4749
4850/// Error that indicates a failure to convert a PyAny to a more specific Python type.
4951#[ derive( Debug ) ]
52+ #[ cfg( feature = "gil-refs" ) ]
5053pub struct PyDowncastError < ' a > {
5154 from : & ' a PyAny ,
5255 to : Cow < ' static , str > ,
5356}
5457
58+ #[ cfg( feature = "gil-refs" ) ]
5559impl < ' a > PyDowncastError < ' a > {
5660 /// Create a new `PyDowncastError` representing a failure to convert the object
5761 /// `from` into the type named in `to`.
@@ -64,7 +68,6 @@ impl<'a> PyDowncastError<'a> {
6468
6569 /// Compatibility API to convert the Bound variant `DowncastError` into the
6670 /// gil-ref variant
67- #[ cfg( feature = "gil-refs" ) ]
6871 pub ( crate ) fn from_downcast_err ( DowncastError { from, to } : DowncastError < ' a , ' a > ) -> Self {
6972 #[ allow( deprecated) ]
7073 let from = unsafe { from. py ( ) . from_borrowed_ptr ( from. as_ptr ( ) ) } ;
@@ -1012,8 +1015,10 @@ impl<'a> std::convert::From<PyDowncastError<'a>> for PyErr {
10121015 }
10131016}
10141017
1018+ #[ cfg( feature = "gil-refs" ) ]
10151019impl < ' a > std:: error:: Error for PyDowncastError < ' a > { }
10161020
1021+ #[ cfg( feature = "gil-refs" ) ]
10171022impl < ' a > std:: fmt:: Display for PyDowncastError < ' a > {
10181023 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
10191024 display_downcast_error ( f, & self . from . as_borrowed ( ) , & self . to )
0 commit comments