1
1
use std:: borrow:: Cow ;
2
2
use std:: str:: from_utf8;
3
3
4
+ use pyo3:: intern2;
4
5
use pyo3:: prelude:: * ;
5
6
use pyo3:: types:: {
6
7
PyBool , PyByteArray , PyBytes , PyDate , PyDateTime , PyDict , PyFloat , PyFrozenSet , PyInt , PyIterator , PyList ,
7
8
PyMapping , PySequence , PySet , PyString , PyTime , PyTuple , PyType ,
8
9
} ;
9
10
#[ cfg( not( PyPy ) ) ]
10
11
use pyo3:: types:: { PyDictItems , PyDictKeys , PyDictValues } ;
11
- use pyo3:: { intern, PyTypeInfo } ;
12
12
13
13
use speedate:: MicrosecondsPrecisionOverflowBehavior ;
14
14
@@ -121,9 +121,9 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
121
121
self . downcast :: < PyDict > ( ) . ok ( ) . map ( Clone :: clone)
122
122
}
123
123
124
- fn input_is_subclass ( & self , class : & PyType ) -> PyResult < bool > {
124
+ fn input_is_subclass ( & self , class : & Py2 < ' _ , PyType > ) -> PyResult < bool > {
125
125
match self . downcast :: < PyType > ( ) {
126
- Ok ( py_type) => py_type. as_gil_ref ( ) . is_subclass ( class) ,
126
+ Ok ( py_type) => py_type. is_subclass ( class) ,
127
127
Err ( _) => Ok ( false ) ,
128
128
}
129
129
}
@@ -204,7 +204,7 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
204
204
Ok ( s) => Ok ( PyString :: new2 ( self . py ( ) , s) . into ( ) ) ,
205
205
Err ( _) => Err ( ValError :: new ( ErrorTypeDefaults :: StringUnicode , self ) ) ,
206
206
}
207
- } else if coerce_numbers_to_str && !PyBool :: is_exact_type_of ( self . as_gil_ref ( ) ) && {
207
+ } else if coerce_numbers_to_str && !self . is_exact_instance_of :: < PyBool > ( ) && {
208
208
let py = self . py ( ) ;
209
209
let decimal_type = get_decimal_type ( py) ;
210
210
@@ -235,7 +235,7 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
235
235
}
236
236
237
237
fn exact_int ( & ' a self ) -> ValResult < EitherInt < ' a > > {
238
- if PyInt :: is_exact_type_of ( self . as_gil_ref ( ) ) {
238
+ if self . is_exact_instance_of :: < PyInt > ( ) {
239
239
Ok ( EitherInt :: Py ( self . clone ( ) ) )
240
240
} else {
241
241
Err ( ValError :: new ( ErrorTypeDefaults :: IntType , self ) )
@@ -244,9 +244,9 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
244
244
245
245
fn validate_bytes ( & ' a self , strict : bool ) -> ValResult < ValidationMatch < EitherBytes < ' a > > > {
246
246
if let Ok ( py_bytes) = self . downcast_exact :: < PyBytes > ( ) {
247
- return Ok ( ValidationMatch :: exact ( py_bytes. as_gil_ref ( ) . into ( ) ) ) ;
247
+ return Ok ( ValidationMatch :: exact ( py_bytes. into ( ) ) ) ;
248
248
} else if let Ok ( py_bytes) = self . downcast :: < PyBytes > ( ) {
249
- return Ok ( ValidationMatch :: strict ( py_bytes. as_gil_ref ( ) . into ( ) ) ) ;
249
+ return Ok ( ValidationMatch :: strict ( py_bytes. into ( ) ) ) ;
250
250
}
251
251
252
252
' lax: {
@@ -304,7 +304,7 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
304
304
} ;
305
305
306
306
// force to an int to upcast to a pure python int
307
- return EitherInt :: upcast ( self . as_gil_ref ( ) ) . map ( |either_int| ValidationMatch :: new ( either_int, exactness) ) ;
307
+ return EitherInt :: upcast ( self ) . map ( |either_int| ValidationMatch :: new ( either_int, exactness) ) ;
308
308
}
309
309
310
310
' lax: {
@@ -331,7 +331,7 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
331
331
332
332
fn validate_float ( & ' a self , strict : bool ) -> ValResult < ValidationMatch < EitherFloat < ' a > > > {
333
333
if let Ok ( float) = self . downcast_exact :: < PyFloat > ( ) {
334
- return Ok ( ValidationMatch :: exact ( EitherFloat :: Py ( float. as_gil_ref ( ) ) ) ) ;
334
+ return Ok ( ValidationMatch :: exact ( EitherFloat :: Py ( float. clone ( ) ) ) ) ;
335
335
}
336
336
337
337
if !strict {
@@ -565,7 +565,7 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
565
565
566
566
fn validate_iter ( & self ) -> ValResult < GenericIterator > {
567
567
if self . iter ( ) . is_ok ( ) {
568
- Ok ( self . as_gil_ref ( ) . into ( ) )
568
+ Ok ( self . into ( ) )
569
569
} else {
570
570
Err ( ValError :: new ( ErrorTypeDefaults :: IterableType , self ) )
571
571
}
@@ -574,7 +574,7 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
574
574
fn validate_date ( & self , strict : bool ) -> ValResult < ValidationMatch < EitherDate > > {
575
575
if let Ok ( date) = self . downcast_exact :: < PyDate > ( ) {
576
576
Ok ( ValidationMatch :: exact ( date. clone ( ) . into ( ) ) )
577
- } else if PyDateTime :: is_type_of ( self . as_gil_ref ( ) ) {
577
+ } else if self . is_instance_of :: < PyDateTime > ( ) {
578
578
// have to check if it's a datetime first, otherwise the line below converts to a date
579
579
// even if we later try coercion from a datetime, we don't want to return a datetime now
580
580
Err ( ValError :: new ( ErrorTypeDefaults :: DateType , self ) )
@@ -616,7 +616,7 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
616
616
bytes_as_time ( self , str. as_bytes ( ) , microseconds_overflow_behavior)
617
617
} else if let Ok ( py_bytes) = self . downcast :: < PyBytes > ( ) {
618
618
bytes_as_time ( self , py_bytes. as_bytes ( ) , microseconds_overflow_behavior)
619
- } else if PyBool :: is_exact_type_of ( self . as_gil_ref ( ) ) {
619
+ } else if self . is_exact_instance_of :: < PyBool > ( ) {
620
620
Err ( ValError :: new ( ErrorTypeDefaults :: TimeType , self ) )
621
621
} else if let Ok ( int) = extract_i64 ( self ) {
622
622
int_as_time ( self , int, 0 )
@@ -650,14 +650,14 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
650
650
bytes_as_datetime ( self , str. as_bytes ( ) , microseconds_overflow_behavior)
651
651
} else if let Ok ( py_bytes) = self . downcast :: < PyBytes > ( ) {
652
652
bytes_as_datetime ( self , py_bytes. as_bytes ( ) , microseconds_overflow_behavior)
653
- } else if PyBool :: is_exact_type_of ( self . as_gil_ref ( ) ) {
653
+ } else if self . is_exact_instance_of :: < PyBool > ( ) {
654
654
Err ( ValError :: new ( ErrorTypeDefaults :: DatetimeType , self ) )
655
655
} else if let Ok ( int) = extract_i64 ( self ) {
656
656
int_as_datetime ( self , int, 0 )
657
657
} else if let Ok ( float) = self . extract :: < f64 > ( ) {
658
658
float_as_datetime ( self , float)
659
659
} else if let Ok ( date) = self . downcast :: < PyDate > ( ) {
660
- Ok ( date_as_datetime ( date. as_gil_ref ( ) ) ?)
660
+ Ok ( date_as_datetime ( date) ?)
661
661
} else {
662
662
break ' lax;
663
663
}
@@ -735,7 +735,7 @@ impl BorrowInput for Py2Borrowed<'_, '_, PyAny> {
735
735
fn from_attributes_applicable ( obj : & Py2 < ' _ , PyAny > ) -> bool {
736
736
let Some ( module_name) = obj
737
737
. get_type ( )
738
- . getattr ( intern ! ( obj. py( ) , "__module__" ) )
738
+ . getattr ( intern2 ! ( obj. py( ) , "__module__" ) )
739
739
. ok ( )
740
740
. and_then ( |module_name| module_name. downcast_into :: < PyString > ( ) . ok ( ) )
741
741
else {
@@ -769,7 +769,7 @@ fn maybe_as_enum<'py>(v: &Py2<'py, PyAny>) -> Option<Py2<'py, PyAny>> {
769
769
let enum_meta_object = get_enum_meta_object ( py) ;
770
770
let meta_type = v. get_type ( ) . get_type ( ) ;
771
771
if meta_type. is ( enum_meta_object) {
772
- v. getattr ( intern ! ( py, "value" ) ) . ok ( )
772
+ v. getattr ( intern2 ! ( py, "value" ) ) . ok ( )
773
773
} else {
774
774
None
775
775
}
0 commit comments