@@ -48,35 +48,6 @@ use super::{
48
48
Input ,
49
49
} ;
50
50
51
- static ORDERED_DICT_TYPE : PyOnceLock < Py < PyType > > = PyOnceLock :: new ( ) ;
52
-
53
- fn get_ordered_dict_type ( py : Python < ' _ > ) -> & Bound < ' _ , PyType > {
54
- ORDERED_DICT_TYPE
55
- . get_or_init ( py, || {
56
- py. import ( "collections" )
57
- . and_then ( |collections_module| collections_module. getattr ( "OrderedDict" ) )
58
- . unwrap ( )
59
- . extract ( )
60
- . unwrap ( )
61
- } )
62
- . bind ( py)
63
- }
64
-
65
- fn check_if_ordered_dict ( obj : & Bound < ' _ , PyAny > ) -> bool {
66
- if obj. is_exact_instance_of :: < PyDict > ( ) {
67
- return false ;
68
- }
69
-
70
- if let Ok ( type_name) = obj. get_type ( ) . name ( ) {
71
- if type_name != "OrderedDict" {
72
- return false ;
73
- }
74
- }
75
-
76
- let ordered_dict_type = get_ordered_dict_type ( obj. py ( ) ) ;
77
- obj. is_instance ( ordered_dict_type) . unwrap_or ( false )
78
- }
79
-
80
51
static FRACTION_TYPE : PyOnceLock < Py < PyType > > = PyOnceLock :: new ( ) ;
81
52
82
53
pub fn get_fraction_type ( py : Python < ' _ > ) -> & Bound < ' _ , PyType > {
@@ -424,19 +395,17 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
424
395
Self : ' a ;
425
396
426
397
fn strict_dict < ' a > ( & ' a self ) -> ValResult < GenericPyMapping < ' a , ' py > > {
427
- if self . is_exact_instance_of :: < PyDict > ( ) {
428
- Ok ( GenericPyMapping :: Dict ( self . downcast :: < PyDict > ( ) ? ) )
429
- } else if check_if_ordered_dict ( self ) {
398
+ if let Ok ( dict ) = self . downcast_exact :: < PyDict > ( ) {
399
+ Ok ( GenericPyMapping :: Dict ( dict ) )
400
+ } else if self . is_instance_of :: < PyDict > ( ) {
430
401
Ok ( GenericPyMapping :: Mapping ( self . downcast :: < PyMapping > ( ) ?) )
431
402
} else {
432
403
Err ( ValError :: new ( ErrorTypeDefaults :: DictType , self ) )
433
404
}
434
405
}
435
406
436
407
fn lax_dict < ' a > ( & ' a self ) -> ValResult < GenericPyMapping < ' a , ' py > > {
437
- if check_if_ordered_dict ( self ) {
438
- Ok ( GenericPyMapping :: Mapping ( self . downcast :: < PyMapping > ( ) ?) )
439
- } else if let Ok ( dict) = self . downcast :: < PyDict > ( ) {
408
+ if let Ok ( dict) = self . downcast_exact :: < PyDict > ( ) {
440
409
Ok ( GenericPyMapping :: Dict ( dict) )
441
410
} else if let Ok ( mapping) = self . downcast :: < PyMapping > ( ) {
442
411
Ok ( GenericPyMapping :: Mapping ( mapping) )
0 commit comments