@@ -24,7 +24,7 @@ impl<'a, 'py> Depythonizer<'a, 'py> {
2424 }
2525
2626 fn sequence_access ( & self , expected_len : Option < usize > ) -> Result < PySequenceAccess < ' a , ' py > > {
27- let seq = self . input . downcast :: < PySequence > ( ) ?;
27+ let seq = self . input . cast :: < PySequence > ( ) ?;
2828 let len = self . input . len ( ) ?;
2929
3030 match expected_len {
@@ -36,10 +36,10 @@ impl<'a, 'py> Depythonizer<'a, 'py> {
3636 }
3737
3838 fn set_access ( & self ) -> Result < PySetAsSequence < ' py > > {
39- match self . input . downcast :: < PySet > ( ) {
39+ match self . input . cast :: < PySet > ( ) {
4040 Ok ( set) => Ok ( PySetAsSequence :: from_set ( set) ) ,
4141 Err ( e) => {
42- if let Ok ( f) = self . input . downcast :: < PyFrozenSet > ( ) {
42+ if let Ok ( f) = self . input . cast :: < PyFrozenSet > ( ) {
4343 Ok ( PySetAsSequence :: from_frozenset ( f) )
4444 } else {
4545 Err ( e. into ( ) )
@@ -49,7 +49,7 @@ impl<'a, 'py> Depythonizer<'a, 'py> {
4949 }
5050
5151 fn dict_access ( & self ) -> Result < PyMappingAccess < ' py > > {
52- PyMappingAccess :: new ( self . input . downcast ( ) ?)
52+ PyMappingAccess :: new ( self . input . cast ( ) ?)
5353 }
5454
5555 fn deserialize_any_int < ' de , V > ( & self , int : & Bound < ' _ , PyInt > , visitor : V ) -> Result < V :: Value >
@@ -111,7 +111,7 @@ impl<'de> de::Deserializer<'de> for &'_ mut Depythonizer<'_, '_> {
111111 self . deserialize_unit ( visitor)
112112 } else if obj. is_instance_of :: < PyBool > ( ) {
113113 self . deserialize_bool ( visitor)
114- } else if let Ok ( x) = obj. downcast :: < PyInt > ( ) {
114+ } else if let Ok ( x) = obj. cast :: < PyInt > ( ) {
115115 self . deserialize_any_int ( x, visitor)
116116 } else if obj. is_instance_of :: < PyList > ( ) || obj. is_instance_of :: < PyTuple > ( ) {
117117 self . deserialize_tuple ( obj. len ( ) ?, visitor)
@@ -128,9 +128,9 @@ impl<'de> de::Deserializer<'de> for &'_ mut Depythonizer<'_, '_> {
128128 self . deserialize_f64 ( visitor)
129129 } else if obj. is_instance_of :: < PyFrozenSet > ( ) || obj. is_instance_of :: < PySet > ( ) {
130130 self . deserialize_seq ( visitor)
131- } else if obj. downcast :: < PySequence > ( ) . is_ok ( ) {
131+ } else if obj. cast :: < PySequence > ( ) . is_ok ( ) {
132132 self . deserialize_tuple ( obj. len ( ) ?, visitor)
133- } else if obj. downcast :: < PyMapping > ( ) . is_ok ( ) {
133+ } else if obj. cast :: < PyMapping > ( ) . is_ok ( ) {
134134 self . deserialize_map ( visitor)
135135 } else {
136136 Err ( obj. get_type ( ) . qualname ( ) . map_or_else (
@@ -151,7 +151,7 @@ impl<'de> de::Deserializer<'de> for &'_ mut Depythonizer<'_, '_> {
151151 where
152152 V : de:: Visitor < ' de > ,
153153 {
154- let s = self . input . downcast :: < PyString > ( ) ?. to_cow ( ) ?;
154+ let s = self . input . cast :: < PyString > ( ) ?. to_cow ( ) ?;
155155 if s. len ( ) != 1 {
156156 return Err ( PythonizeError :: invalid_length_char ( ) ) ;
157157 }
@@ -175,7 +175,7 @@ impl<'de> de::Deserializer<'de> for &'_ mut Depythonizer<'_, '_> {
175175 where
176176 V : de:: Visitor < ' de > ,
177177 {
178- let s = self . input . downcast :: < PyString > ( ) ?;
178+ let s = self . input . cast :: < PyString > ( ) ?;
179179 visitor. visit_str ( & s. to_cow ( ) ?)
180180 }
181181
@@ -190,7 +190,7 @@ impl<'de> de::Deserializer<'de> for &'_ mut Depythonizer<'_, '_> {
190190 where
191191 V : de:: Visitor < ' de > ,
192192 {
193- let b = self . input . downcast :: < PyBytes > ( ) ?;
193+ let b = self . input . cast :: < PyBytes > ( ) ?;
194194 visitor. visit_bytes ( b. as_bytes ( ) )
195195 }
196196
@@ -303,17 +303,17 @@ impl<'de> de::Deserializer<'de> for &'_ mut Depythonizer<'_, '_> {
303303 V : de:: Visitor < ' de > ,
304304 {
305305 let item = & self . input ;
306- if let Ok ( s) = item. downcast :: < PyString > ( ) {
306+ if let Ok ( s) = item. cast :: < PyString > ( ) {
307307 visitor. visit_enum ( s. to_cow ( ) ?. into_deserializer ( ) )
308- } else if let Ok ( m) = item. downcast :: < PyMapping > ( ) {
308+ } else if let Ok ( m) = item. cast :: < PyMapping > ( ) {
309309 // Get the enum variant from the mapping key
310310 if m. len ( ) ? != 1 {
311311 return Err ( PythonizeError :: invalid_length_enum ( ) ) ;
312312 }
313313 let variant: Bound < PyString > = m
314314 . keys ( ) ?
315315 . get_item ( 0 ) ?
316- . downcast_into :: < PyString > ( )
316+ . cast_into :: < PyString > ( )
317317 . map_err ( |_| PythonizeError :: dict_key_not_string ( ) ) ?;
318318 let value = m. get_item ( & variant) ?;
319319 visitor. visit_enum ( PyEnumAccess :: new ( & value, variant) )
@@ -328,7 +328,7 @@ impl<'de> de::Deserializer<'de> for &'_ mut Depythonizer<'_, '_> {
328328 {
329329 let s = self
330330 . input
331- . downcast :: < PyString > ( )
331+ . cast :: < PyString > ( )
332332 . map_err ( |_| PythonizeError :: dict_key_not_string ( ) ) ?;
333333 visitor. visit_str ( & s. to_cow ( ) ?)
334334 }
@@ -528,7 +528,7 @@ mod test {
528528 where
529529 T : de:: DeserializeOwned + PartialEq + std:: fmt:: Debug ,
530530 {
531- Python :: with_gil ( |py| {
531+ Python :: attach ( |py| {
532532 let obj = py. eval ( code, None , None ) . unwrap ( ) ;
533533 let actual: T = depythonize ( & obj) . unwrap ( ) ;
534534 assert_eq ! ( & actual, expected) ;
@@ -585,7 +585,7 @@ mod test {
585585
586586 let code = c_str ! ( "{'foo': 'Foo'}" ) ;
587587
588- Python :: with_gil ( |py| {
588+ Python :: attach ( |py| {
589589 let locals = PyDict :: new ( py) ;
590590 let obj = py. eval ( code, None , Some ( & locals) ) . unwrap ( ) ;
591591 assert ! ( matches!(
@@ -613,7 +613,7 @@ mod test {
613613
614614 let code = c_str ! ( "('cat', -10.05, 'foo')" ) ;
615615
616- Python :: with_gil ( |py| {
616+ Python :: attach ( |py| {
617617 let locals = PyDict :: new ( py) ;
618618 let obj = py. eval ( code, None , Some ( & locals) ) . unwrap ( ) ;
619619 assert ! ( matches!(
@@ -825,7 +825,7 @@ mod test {
825825
826826 #[ test]
827827 fn test_int_limits ( ) {
828- Python :: with_gil ( |py| {
828+ Python :: attach ( |py| {
829829 // serde_json::Value supports u64 and i64 as maximum sizes
830830 let _: serde_json:: Value = depythonize ( & u8:: MAX . into_pyobject ( py) . unwrap ( ) ) . unwrap ( ) ;
831831 let _: serde_json:: Value = depythonize ( & u8:: MIN . into_pyobject ( py) . unwrap ( ) ) . unwrap ( ) ;
@@ -857,7 +857,7 @@ mod test {
857857
858858 #[ test]
859859 fn test_deserialize_bytes ( ) {
860- Python :: with_gil ( |py| {
860+ Python :: attach ( |py| {
861861 let obj = PyBytes :: new ( py, "hello" . as_bytes ( ) ) ;
862862 let actual: Vec < u8 > = depythonize ( & obj) . unwrap ( ) ;
863863 assert_eq ! ( actual, b"hello" ) ;
@@ -874,7 +874,7 @@ mod test {
874874
875875 #[ test]
876876 fn test_unknown_type ( ) {
877- Python :: with_gil ( |py| {
877+ Python :: attach ( |py| {
878878 let obj = py
879879 . import ( "decimal" )
880880 . unwrap ( )
0 commit comments