@@ -316,21 +316,22 @@ impl<'a> Input<'a> for PyAny {
316
316
fn ultra_strict_float ( & ' a self ) -> ValResult < EitherFloat < ' a > > {
317
317
if self . is_instance_of :: < PyInt > ( ) {
318
318
Err ( ValError :: new ( ErrorType :: FloatType , self ) )
319
- } else if self . is_instance_of :: < PyFloat > ( ) {
320
- Ok ( EitherFloat :: Py ( self ) )
319
+ } else if let Ok ( float ) = self . downcast :: < PyFloat > ( ) {
320
+ Ok ( EitherFloat :: Py ( float ) )
321
321
} else {
322
322
Err ( ValError :: new ( ErrorType :: FloatType , self ) )
323
323
}
324
324
}
325
325
fn strict_float ( & ' a self ) -> ValResult < EitherFloat < ' a > > {
326
326
if PyFloat :: is_exact_type_of ( self ) {
327
- Ok ( EitherFloat :: Py ( self ) )
327
+ // Safety: self is PyFloat
328
+ Ok ( EitherFloat :: Py ( unsafe { self . downcast_unchecked :: < PyFloat > ( ) } ) )
328
329
} else if let Ok ( float) = self . extract :: < f64 > ( ) {
329
330
// bools are cast to floats as either 0.0 or 1.0, so check for bool type in this specific case
330
331
if ( float == 0.0 || float == 1.0 ) && PyBool :: is_exact_type_of ( self ) {
331
332
Err ( ValError :: new ( ErrorType :: FloatType , self ) )
332
333
} else {
333
- Ok ( EitherFloat :: Py ( self ) )
334
+ Ok ( EitherFloat :: F64 ( float ) )
334
335
}
335
336
} else {
336
337
Err ( ValError :: new ( ErrorType :: FloatType , self ) )
@@ -339,7 +340,8 @@ impl<'a> Input<'a> for PyAny {
339
340
340
341
fn lax_float ( & ' a self ) -> ValResult < EitherFloat < ' a > > {
341
342
if PyFloat :: is_exact_type_of ( self ) {
342
- Ok ( EitherFloat :: Py ( self ) )
343
+ // Safety: self is PyFloat
344
+ Ok ( EitherFloat :: Py ( unsafe { self . downcast_unchecked :: < PyFloat > ( ) } ) )
343
345
} else if let Some ( cow_str) = maybe_as_string ( self , ErrorType :: FloatParsing ) ? {
344
346
match cow_str. as_ref ( ) . parse :: < f64 > ( ) {
345
347
Ok ( i) => Ok ( EitherFloat :: F64 ( i) ) ,
0 commit comments