@@ -63,17 +63,21 @@ fn get_ordered_dict_type(py: Python<'_>) -> &Bound<'_, PyType> {
63
63
}
64
64
65
65
fn check_if_ordered_dict ( obj : & Bound < ' _ , PyAny > ) -> bool {
66
+ println ! ( "check_if_ordered_dict: {:?}" , obj) ;
66
67
if obj. is_exact_instance_of :: < PyDict > ( ) {
68
+ println ! ( "is exact dict" ) ;
67
69
return false ;
68
70
}
69
71
70
72
if let Ok ( type_name) = obj. get_type ( ) . name ( ) {
73
+ println ! ( "this is the type name: {}" , type_name) ;
71
74
if type_name. to_string ( ) != "OrderedDict" {
72
75
return false ;
73
76
}
74
77
}
75
78
76
79
let ordered_dict_type = get_ordered_dict_type ( obj. py ( ) ) ;
80
+ println ! ( "is ordered dict type: {}" , ordered_dict_type) ;
77
81
obj. is_instance ( ordered_dict_type) . unwrap_or ( false )
78
82
}
79
83
@@ -424,26 +428,19 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
424
428
Self : ' a ;
425
429
426
430
fn strict_dict < ' a > ( & ' a self ) -> ValResult < GenericPyMapping < ' a , ' py > > {
427
- if let Ok ( dict) = self . downcast :: < PyDict > ( ) {
428
- Ok ( GenericPyMapping :: Dict ( dict) )
429
- } else {
431
+ if self . is_exact_instance_of :: < PyDict > ( ) {
432
+ Ok ( GenericPyMapping :: Dict ( self . downcast :: < PyDict > ( ) ?) )
433
+ } else if check_if_ordered_dict ( self ) {
434
+ Ok ( GenericPyMapping :: Mapping ( self . downcast :: < PyMapping > ( ) ?) )
435
+ }
436
+ else {
430
437
Err ( ValError :: new ( ErrorTypeDefaults :: DictType , self ) )
431
438
}
432
439
}
433
440
434
441
fn lax_dict < ' a > ( & ' a self ) -> ValResult < GenericPyMapping < ' a , ' py > > {
435
-
436
- if check_if_ordered_dict ( self ) {
437
- // OrderedDict is a subclass of dict, but we want to treat it as a mapping to preserve order
438
- if let Ok ( mapping) = self . downcast :: < PyMapping > ( ) {
439
- return Ok ( GenericPyMapping :: Mapping ( mapping) ) ;
440
- }
441
- }
442
-
443
- if let Ok ( dict) = self . downcast :: < PyDict > ( ) {
444
- Ok ( GenericPyMapping :: Dict ( dict) )
445
- } else if let Ok ( mapping) = self . downcast :: < PyMapping > ( ) {
446
- Ok ( GenericPyMapping :: Mapping ( mapping) )
442
+ if ( self . is_instance_of :: < PyDict > ( ) || self . is_instance_of :: < PyMapping > ( ) ) {
443
+ Ok ( GenericPyMapping :: Mapping ( self . downcast :: < PyMapping > ( ) ?) )
447
444
} else {
448
445
Err ( ValError :: new ( ErrorTypeDefaults :: DictType , self ) )
449
446
}
0 commit comments