@@ -312,33 +312,39 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
312
312
313
313
// Fast path for existing decimal objects
314
314
if self . is_exact_instance ( decimal_type) {
315
- Ok ( ValidationMatch :: exact ( self . to_owned ( ) . clone ( ) ) )
316
- } else if self . is_instance ( decimal_type) ? {
317
- // Upcast subclasses to decimal
318
- create_decimal ( self , self ) . map ( ValidationMatch :: strict)
319
- } else {
320
- if strict {
321
- return Err ( ValError :: new (
322
- ErrorType :: IsInstanceOf {
323
- class : decimal_type
324
- . qualname ( )
325
- . and_then ( |name| name. extract ( ) )
326
- . unwrap_or_else ( |_| "Decimal" . to_owned ( ) ) ,
327
- context : None ,
328
- } ,
329
- self ,
330
- ) ) ;
331
- }
315
+ return Ok ( ValidationMatch :: exact ( self . to_owned ( ) . clone ( ) ) ) ;
316
+ }
317
+
318
+ if !strict {
332
319
if self . is_instance_of :: < PyString > ( ) || ( self . is_instance_of :: < PyInt > ( ) && !self . is_instance_of :: < PyBool > ( ) )
333
320
{
334
321
// Checking isinstance for str / int / bool is fast compared to decimal / float
335
- create_decimal ( self , self ) . map ( ValidationMatch :: lax)
336
- } else if self . is_instance_of :: < PyFloat > ( ) {
337
- create_decimal ( self . str ( ) ?. as_any ( ) , self ) . map ( ValidationMatch :: lax)
338
- } else {
339
- Err ( ValError :: new ( ErrorTypeDefaults :: DecimalType , self ) )
322
+ return create_decimal ( self , self ) . map ( ValidationMatch :: lax) ;
340
323
}
324
+
325
+ if self . is_instance_of :: < PyFloat > ( ) {
326
+ return create_decimal ( self . str ( ) ?. as_any ( ) , self ) . map ( ValidationMatch :: lax) ;
327
+ }
328
+ }
329
+
330
+ if self . is_instance ( decimal_type) ? {
331
+ // Upcast subclasses to decimal
332
+ return create_decimal ( self , self ) . map ( ValidationMatch :: strict) ;
341
333
}
334
+
335
+ let error_type = if strict {
336
+ ErrorType :: IsInstanceOf {
337
+ class : decimal_type
338
+ . qualname ( )
339
+ . and_then ( |name| name. extract ( ) )
340
+ . unwrap_or_else ( |_| "Decimal" . to_owned ( ) ) ,
341
+ context : None ,
342
+ }
343
+ } else {
344
+ ErrorTypeDefaults :: DecimalType
345
+ } ;
346
+
347
+ Err ( ValError :: new ( error_type, self ) )
342
348
}
343
349
344
350
type Dict < ' a > = GenericPyMapping < ' a , ' py > where Self : ' a ;
0 commit comments